-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.server.config.js
107 lines (93 loc) · 2.34 KB
/
webpack.server.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
const webpack = require('webpack');
const path = require('path');
const fs = require('fs');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const isProduction = process.env.NODE_ENV === 'production' ? true : false;
// production settings
const HOST = process.env.HOST || "0.0.0.0";
const PORT = process.env.PORT || "9000";
let nodeModules = {};
fs.readdirSync('node_modules')
.filter(function(x) {
return ['.bin'].indexOf(x) === -1;
})
.forEach(function(mod) {
nodeModules[mod] = 'commonjs ' + mod;
});
const config = {
context: __dirname,
devtool: isProduction ? null : 'source-map',
entry: []
.concat(!isProduction && [
'webpack/hot/poll?1000',
])
.concat([
'./server/index.js',
])
.filter(x => !!x),
target: 'node',
node: {
__dirname: false,
__filename: false,
},
output: {
path: path.join(__dirname, 'build'),
publicPath: path.join(__dirname, 'build'),
filename: 'backend.js'
},
externals: nodeModules,
resolve: {
root: [
path.resolve(__dirname),
],
modulesDirectories: ['node_modules'],
extensions: ['', '.js'],
},
plugins: []
.concat([
new webpack.NoErrorsPlugin(),
new webpack.IgnorePlugin(/\.(css|less)$/),
new CleanWebpackPlugin(['build'], {
root: __dirname,
verbose: true,
dry: false,
exclude: ['backend.js'],
}),
])
.concat(isProduction && [
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("production"),
HOST: JSON.stringify(HOST),
PORT: JSON.stringify(PORT),
},
__DEVELOPMENT__: false,
__DEVTOOLS__: false,
}),
new webpack.optimize.UglifyJsPlugin({
compress: { warnings: false },
}),
])
.concat(!isProduction && [
new webpack.DefinePlugin({
__DEVELOPMENT__: true,
__DEVTOOLS__: false,
}),
new webpack.BannerPlugin(
'require("source-map-support").install();',
{ raw: true, entryOnly: false }
),
new webpack.HotModuleReplacementPlugin(),
])
.filter(x => !!x),
module: {
loaders: [
{
test: /\.js?$/,
exclude: /(node_modules|bower_components)/,
loaders: isProduction ? ['babel'] : ['express-hot', 'babel'],
},
],
},
};
module.exports = config;