-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (43 loc) · 1.35 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const path = require('path')
const ServerlessWebpack = require('serverless-webpack')
const getConfig = (servicePath, bundlerOptions) => {
const pathToWebpackConfig = `${path.relative(
servicePath,
__dirname,
)}/config/webpack.config.js`
return {
webpack: {
packager: 'yarn',
excludeFiles: '**/{index.yml,index.spec.js}',
webpackConfig: pathToWebpackConfig,
...bundlerOptions,
// if we are outputting stats, we probably want to
// keep the webpack folder so we can analyze them
...(bundlerOptions.outputStats && {
keepOutputDirectory: true,
}),
},
}
}
class ServerlessPlugin extends ServerlessWebpack {
constructor(serverless, options) {
super(serverless, options)
this.serverless = serverless
this.options = options
const {
custom: {webpack = null, serverless_bundler = {}} = {},
} = this.serverless.service
this.hooks['before:webpack:validate:validate'] = function validate() {
if (webpack) {
throw new Error(
'serverless-webpack config detected in serverless.yml. serverless-bundle is not compatible with serverless-webpack.',
)
}
this.serverless.service.custom = getConfig(
this.serverless.config.servicePath,
serverless_bundler,
)
}.bind(this)
}
}
module.exports = ServerlessPlugin