-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathwebpack.node.config.js
58 lines (52 loc) · 1.48 KB
/
webpack.node.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
require('babel-polyfill')
const Path = require('path')
const Webpack = require('webpack')
const OPTIMIZE = true
const appEntry = Path.join(__dirname, 'server/server')
const plugins = []
if (OPTIMIZE) {
plugins.push(new Webpack.optimize.OccurrenceOrderPlugin(true))
plugins.push(new Webpack.optimize.DedupePlugin())
plugins.push(new Webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
unused: true,
dead_code: true,
drop_console: true,
},
output: {
comments: false
},
// turn off mangling entirely in case of variable rename
sourceMap: false,
// mangle can make node stop working because of some global variables
// mangle: true
}))
}
const conf = {
target: 'node',
output: {
path: Path.join(__dirname, 'build/node'),
filename: 'index.js',
libraryTarget: 'commonjs',
},
externals: [
// these modules will be included because of dynamic resolvers
/^(?:express|graphql|sequelize|bindings|multer|isomorphic-fetch)/i,
],
module: {
rules: [
// if we have many code then use cacheDirectory, but this time almost code is on node_modules
// ?cacheDirectory=true
{ test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/, query:{cacheDirectory: true} },
{ test: /\.json$/, loader: 'json-loader'},
]
},
resolve: {
extensions: ['.js'],
modules: ['node_modules', './server'],
},
plugins: plugins,
}
conf.entry = [appEntry]
module.exports = conf