This repository has been archived by the owner on Feb 25, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.server.js
96 lines (92 loc) · 1.95 KB
/
webpack.server.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
const webpack = require('webpack');
const path = require('path');
const { readFileSync } = require('fs');
const nodeExternals = require('webpack-node-externals');
const StartServerPlugin = require('start-server-webpack-plugin');
const DEV = process.env.NODE_ENV !== 'production';
const plugins = [
new webpack.NamedModulesPlugin(),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.DefinePlugin({
'process.env': {
BUILD_TARGET: JSON.stringify('server'),
NODE_ENV: DEV ? JSON.stringify('development') : JSON.stringify('production')
},
})
];
if (DEV) {
plugins.push(
new StartServerPlugin({
name: 'server.js',
nodeArgs: ['--inspect']
})
);
}
module.exports = {
devtool: DEV ? 'inline-source-map' : 'source-map',
entry: DEV ? [
'webpack/hot/poll?1000',
'./src/server'
] : [
'./src/server'
],
resolve: {
extensions: ['.js', '.jsx']
},
output: {
path: path.join(__dirname, '/.build'),
filename: 'server.js'
},
target: 'node',
externals: DEV ? [
nodeExternals({ whitelist: ['webpack/hot/poll?1000'] })
] : [
nodeExternals()
],
module: {
rules: [
{
test: /\.(js)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
query: {
presets: [
['env', {
modules: false,
targets: {
node: 'current'
},
exclude: ['transform-regenerator']
}]
],
plugins: [
[
'transform-react-jsx',
{
'pragma': 'h'
}
],
'transform-object-rest-spread',
'syntax-jsx',
'syntax-flow',
'transform-flow-strip-types'
]
}
}
}, {
test: /\.(png|jpg|gif|svg)$/,
loader: 'url-loader',
options: {
limit: 1,
name: '[name].[hash].[ext]'
}
}, {
test: /\.scss$/,
use: 'null-loader'
}
]
},
plugins: plugins // eslint-disable-line
};