forked from nasa/earthdata-search
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverless.webpack.config.js
72 lines (65 loc) · 1.73 KB
/
serverless.webpack.config.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const path = require('path')
const slsw = require('serverless-webpack')
const nodeExternals = require('webpack-node-externals')
const CopyPlugin = require('copy-webpack-plugin')
// Allow for conditionally copying files into the output for a defined entry
const ConditionalPlugin = (condition, plugin) => ({
apply: (compiler) => {
const name = Object.keys(compiler.options.entry)[0].split('/')
// Pull the filename of the Lambda
let fileName = name.pop()
// For lambdas that have been updated to the new `serverless/src/LAMBDA/handler.js`
if (fileName === 'handler') {
fileName = name.pop()
}
const config = {
webpack: {},
...slsw.lib.serverless.service.getFunction(fileName)
}
if (condition(config)) {
plugin.apply(compiler)
}
}
})
const ServerlessWebpackConfig = {
name: 'serverless',
mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
entry: slsw.lib.entries,
target: 'node',
output: {
path: path.resolve(__dirname, 'serverless/dist'),
filename: '[name].js',
libraryTarget: 'commonjs',
clean: true // Replaces CleanWebpackPlugin in Webpack 5
},
externalsPresets: {
node: true
},
externals: [
nodeExternals()
],
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: [
{ loader: 'babel-loader' }
]
}
]
},
plugins: [
// new CleanWebpackPlugin([path.resolve(__dirname, 'serverless/dist')]),
ConditionalPlugin(
((config) => config.webpack.includeMigrations),
new CopyPlugin({
patterns: [
{ from: 'migrations', to: 'migrations' }
]
})
)
// new ESLintPlugin()
]
}
module.exports = ServerlessWebpackConfig