Skip to content

Commit

Permalink
Merge branch 'master' into remove-warning
Browse files Browse the repository at this point in the history
  • Loading branch information
designfrontier authored Apr 7, 2019
2 parents 824458d + 89cacfc commit 342702f
Show file tree
Hide file tree
Showing 14 changed files with 1,185 additions and 1,137 deletions.
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ A basic Webpack promise configuration might look like this:
const webpack = require('webpack')
const slsw = require('serverless-webpack');
module.exports = async () => {
module.exports = (async () => {
const accountId = await slsw.lib.serverless.providers.aws.getAccountId();
return {
entry: './handler.js',
Expand All @@ -113,7 +113,7 @@ module.exports = async () => {
loaders: [ ... ]
}
};
}();
})();
```
```js
// Version with promises
Expand Down Expand Up @@ -184,6 +184,8 @@ module.exports = {
The lib export also provides the `serverless` and `options` properties, through
which you can access the Serverless instance and the options given on the command-line.
The current stage e.g is accessible through `slsw.lib.options.stage`
This enables you to have a fully customized dynamic configuration, that can evaluate
anything available in the Serverless framework. There are really no limits.
Expand Down Expand Up @@ -228,7 +230,7 @@ const path = require('path');
module.exports = {
// ...
output: {
libraryTarget: 'commonjs',
libraryTarget: 'commonjs2',
path: path.resolve(__dirname, '.webpack'),
filename: '[name].js',
},
Expand Down Expand Up @@ -450,6 +452,23 @@ custom:
This is also useful for projects that use TypeScript.
#### Keep output directory after packaging
You can keep the output directory (defaults to `.webpack`) from being removed
after build.
Just add `keepOutputDirectory: true`
```yaml
# serverless.yml
custom:
webpack:
keepOutputDirectory: true
```
This can be useful, in case you want to upload the source maps to your Error
reporting system, or just have it available for some post processing.
#### Examples
You can find an example setups in the [`examples`][link-examples] folder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
]
},
output: {
libraryTarget: 'commonjs',
libraryTarget: 'commonjs2',
path: path.join(__dirname, '.webpack'),
filename: '[name].js'
}
Expand Down
2 changes: 1 addition & 1 deletion examples/babel/serverless.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
service: babel-dynamically-entries-example
service: babel-example

# Add the serverless-webpack plugin
plugins:
Expand Down
2 changes: 1 addition & 1 deletion examples/babel/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = {
]
},
output: {
libraryTarget: 'commonjs',
libraryTarget: 'commonjs2',
path: path.join(__dirname, '.webpack'),
filename: '[name].js'
}
Expand Down
2 changes: 1 addition & 1 deletion examples/multiple-statically-entries/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = {
},
target: 'node',
output: {
libraryTarget: 'commonjs',
libraryTarget: 'commonjs2',
path: path.join(__dirname, '.webpack'),
filename: '[name].js'
},
Expand Down
2 changes: 1 addition & 1 deletion examples/serverless-offline/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
target: 'node',
externals: [nodeExternals()],
output: {
libraryTarget: 'commonjs',
libraryTarget: 'commonjs2',
path: path.join(__dirname, '.webpack'),
filename: '[name].js'
},
Expand Down
2 changes: 1 addition & 1 deletion examples/typescript/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = {
]
},
output: {
libraryTarget: 'commonjs',
libraryTarget: 'commonjs2',
path: path.join(__dirname, '.webpack'),
filename: '[name].js'
},
Expand Down
5 changes: 5 additions & 0 deletions lib/Configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const DefaultConfig = {
includeModules: false,
packager: 'npm',
packagerOptions: {},
keepOutputDirectory: false,
config: null
};

Expand Down Expand Up @@ -70,6 +71,10 @@ class Configuration {
return this._hasLegacyConfig;
}

get keepOutputDirectory() {
return this._config.keepOutputDirectory;
}

toJSON() {
return _.omitBy(this._config, _.isNil);
}
Expand Down
4 changes: 4 additions & 0 deletions lib/Configuration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('Configuration', () => {
includeModules: false,
packager: 'npm',
packagerOptions: {},
keepOutputDirectory: false,
config: null
};
});
Expand Down Expand Up @@ -66,6 +67,7 @@ describe('Configuration', () => {
includeModules: { forceInclude: ['mod1'] },
packager: 'npm',
packagerOptions: {},
keepOutputDirectory: false,
config: null
});
});
Expand All @@ -85,6 +87,7 @@ describe('Configuration', () => {
includeModules: { forceInclude: ['mod1'] },
packager: 'npm',
packagerOptions: {},
keepOutputDirectory: false,
config: null
});
});
Expand All @@ -103,6 +106,7 @@ describe('Configuration', () => {
includeModules: { forceInclude: ['mod1'] },
packager: 'npm',
packagerOptions: {},
keepOutputDirectory: false,
config: null
});
});
Expand Down
12 changes: 8 additions & 4 deletions lib/cleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ module.exports = {
cleanup() {
const webpackOutputPath = this.webpackOutputPath;

this.options.verbose && this.serverless.cli.log(`Remove ${webpackOutputPath}`);

if (this.serverless.utils.dirExistsSync(webpackOutputPath)) {
fse.removeSync(webpackOutputPath);
const keepOutputDirectory = this.configuration.keepOutputDirectory;
if (!keepOutputDirectory) {
this.options.verbose && this.serverless.cli.log(`Remove ${webpackOutputPath}`);
if (this.serverless.utils.dirExistsSync(webpackOutputPath)) {
fse.removeSync(webpackOutputPath);
}
} else {
this.options.verbose && this.serverless.cli.log(`Keeping ${webpackOutputPath}`);
}

return BbPromise.resolve();
Expand Down
2 changes: 1 addition & 1 deletion lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ module.exports = {
if (!this.webpackConfig.output || _.isEmpty(this.webpackConfig.output)) {
const outputPath = path.join(this.serverless.config.servicePath, '.webpack');
this.webpackConfig.output = {
libraryTarget: 'commonjs',
libraryTarget: 'commonjs2',
path: outputPath,
filename: '[name].js',
};
Expand Down
Loading

0 comments on commit 342702f

Please sign in to comment.