Skip to content

Commit

Permalink
Add option for custom webpack configuration file (#25)
Browse files Browse the repository at this point in the history
Fixes #24
  • Loading branch information
jogold authored Jun 20, 2017
1 parent 779b7b1 commit 3db1047
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ plugins:
The plugin will add `'**'` as an `exclude` at the service level and each bundled javascript file as an `include` at the function level. Original includes and excludes specified in your `serverless.yml` are preserved.

## Webpack configuration
The plugin will look for a `webpack.config.js` in the service root.
By default the plugin will look for a `webpack.config.js` in the service root. You can specify a custom config file in your `serverless.yml`:
```yaml
custom:
webpack:
config: ./path/to/config/file.js
```

The `entry` and `output` objects are set by the plugin.

Expand Down
10 changes: 7 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ const wpack = require('./lib/wpack');
const serverlessFolder = '.serverless';
const webpackFolder = '.webpack';

// Webpack default output
// Webpack defaults
const webpackDefaultOutput = {
libraryTarget: 'commonjs2',
filename: '[name]',
};
const webpackDefaultConfig = 'webpack.config.js';

class ServerlessPluginWebpack {
constructor(serverless, options) {
this.serverless = serverless;
this.options = options;

this.custom = R.pathOr({}, ['custom', 'webpack'], this.serverless.service);
this.hooks = {
'before:package:createDeploymentArtifacts': () => this.webpackBundle('service'),
'after:package:createDeploymentArtifacts': () => this.restoreAndCopy('service'),
Expand All @@ -32,7 +33,10 @@ class ServerlessPluginWebpack {

// Load webpack config
// eslint-disable-next-line global-require, import/no-dynamic-require
const webpackConfig = require(path.join(this.serverless.config.servicePath, 'webpack.config.js'));
const webpackConfig = require(path.join(
this.serverless.config.servicePath,
this.custom.config || webpackDefaultConfig
));

// Save original service path and functions
this.originalServicePath = this.serverless.config.servicePath;
Expand Down

0 comments on commit 3db1047

Please sign in to comment.