This repository was archived by the owner on Feb 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebpack.config.js
77 lines (75 loc) · 2.37 KB
/
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
73
74
75
76
77
const { join } = require(`path`)
const slsw = require(`serverless-webpack`) // https://github.com/serverless-heaven/serverless-webpack
const nodeExternals = require(`webpack-node-externals`) // https://github.com/liady/webpack-node-externals
const MinifyPlugin = require(`babel-minify-webpack-plugin`) // https://github.com/webpack-contrib/babel-minify-webpack-plugin
const LodashModuleReplacementPlugin = require(`lodash-webpack-plugin`) // https://github.com/lodash/lodash-webpack-plugin
const { optimize } = require(`webpack`)
const { ModuleConcatenationPlugin } = optimize
const ENV = process.env.NODE_ENV && process.env.NODE_ENV.toLowerCase() || (process.env.NODE_ENV = `development`)
//const envDev = ENV === `development`
const envProd = ENV === `production`
//const envTest = ENV === `test`
const srcDir = join(__dirname, `src`)
const outDir = join(__dirname, `dist`)
const npmDir = join(__dirname, `node_modules`)
module.exports = {
entry: slsw.lib.entries,
target: `node`,
externals: [
nodeExternals({
modulesFromFile: true
})
],
output: {
libraryTarget: `commonjs`,
path: outDir,
filename: `[name].js`
},
stats: {
colors: true,
reasons: false,
chunks: false
},
performance: {
hints: false
},
// https://webpack.js.org/configuration/resolve/
resolve: {
extensions: [`.js`, `.json`, `.gql`, `.graphql`],
alias: {
'@': srcDir
}
},
module: {
rules: [
{ test: /\.js$/, loader: `babel-loader`, exclude: npmDir },
{ test: /\.json$/, loader: `json-loader` },
{ test: /\.(graphql|gql)$/, exclude: npmDir, loader: `graphql-tag/loader` }
]
},
plugins: [
new LodashModuleReplacementPlugin(),
// https://webpack.js.org/plugins/module-concatenation-plugin/
new ModuleConcatenationPlugin(),
// https://github.com/babel/minify/tree/master/packages/babel-preset-minify#options
new MinifyPlugin({
keepFnName: true,
keepClassName: true,
booleans: envProd,
deadcode: true,
evaluate: envProd,
flipComparisons: envProd,
mangle: false,
memberExpressions: envProd,
mergeVars: envProd,
numericLiterals: envProd,
propertyLiterals: envProd,
removeConsole: envProd,
removeDebugger: envProd,
simplify: envProd,
simplifyComparisons: envProd,
typeConstructors: envProd,
undefinedToVoid: envProd
})
]
}