forked from AnomalyInnovations/serverless-bundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (39 loc) · 1.29 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
52
53
"use strict";
const path = require("path");
const ServerlessWebpack = require("serverless-webpack");
const config = require("./src/config");
function getWebpackConfigPath(servicePath) {
return path.relative(servicePath, __dirname) + "/src/webpack.config.js";
}
function getConfig(custom, servicePath) {
const webpackConfigPath = getWebpackConfigPath(servicePath);
if (custom) {
if (custom.webpack) {
throw "serverless-webpack config detected in serverless.yml. serverless-bundle is not compatible with serverless-webpack.";
}
custom.webpack = {
webpackConfig: webpackConfigPath
};
return custom;
}
return {
webpack: {
webpackConfig: webpackConfigPath
}
};
}
class ServerlessPlugin extends ServerlessWebpack {
constructor(serverless, options) {
super(serverless, options);
this.serverless = serverless;
this.options = options;
this.hooks["before:webpack:validate:validate"] = function() {
const service = this.serverless.service;
const servicePath = this.serverless.config.servicePath;
service.custom = getConfig(service.custom, servicePath);
config.servicePath = servicePath;
config.options = Object.assign(config.options, service.custom.bundle);
}.bind(this);
}
}
module.exports = ServerlessPlugin;