forked from huksley/todo-react-ssr-serverless
-
Notifications
You must be signed in to change notification settings - Fork 4
/
webpack.serverless.js
81 lines (78 loc) · 2.05 KB
/
webpack.serverless.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
73
74
75
76
77
78
79
80
81
const path = require('path');
const serverless = require('serverless-webpack');
const nodeExternals = require('webpack-node-externals');
const webpack = require('webpack');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const resolve = {
extensions: ['.js', '.jsx'],
};
const config = {
entry: serverless.lib.entries,
mode: serverless.lib.webpack.isLocal ? 'development' : 'production',
target: 'node',
node: {
__dirname: false
},
optimization: {
// We no not want to minimize our code.
minimize: false
},
devtool: serverless.lib.webpack.isLocal ? 'source-map' : 'source-map',
externals: [ nodeExternals() ],
output: {
libraryTarget: 'commonjs2',
// Write to folder which serverless-webpack expects
path: path.resolve(__dirname, '.webpack'),
filename: '[name].js',
strictModuleExceptionHandling: true
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: require.resolve('babel-loader'),
options: {
presets: [
[ '@babel/env', {
targets: {
node: '8.10'
}
}
]
]
}
}
},
{
test: /\.(gif|png|jpe?g|svg)$/i,
use: [
'file-loader',
{
loader: 'image-webpack-loader',
options: {
bypassOnDebug: true
}
}
]
}
]
},
resolve,
// For serverless, everything needed must be copied to output folder
plugins: [
// Copy all used resources (no dir available)
new CopyWebpackPlugin([
{ from: "dist", to: "dist" }
]),
// Limit chunks to 1 effectively disable chunking (used in dynamic imports)
// Dos not
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1
})
]
};
// Never export multiple or 1-array entries, as serverless-webpack cannot handle those
module.exports = config;