-
Notifications
You must be signed in to change notification settings - Fork 5
/
webpack.config.server.js
120 lines (117 loc) · 3.09 KB
/
webpack.config.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
'use strict'
const path = require('path')
const webpack = require('webpack')
const nodeExternals = require('webpack-node-externals')
const StartServerPlugin = require('start-server-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const publicPath = path.resolve(__dirname, './src/server')
const buildPath = path.resolve(__dirname, './src')
const postcssPath = path.resolve(__dirname, './src/client')
const WebpackCleanupPlugin = require('webpack-cleanup-plugin')
const BrowserSyncPlugin = require('browser-sync-webpack-plugin')
process.noDeprecation = true
module.exports = {
devtool: 'source-map',
performance: {
hints: false
},
watch: true,
/* tells webpack to ignore built-in modules like path, fs, etc. */
target: 'node',
node: {
__dirname: true,
__filename: true
},
context: publicPath,
entry: {
bundle: [
'webpack/hot/poll?1000',
'./devServer'
]
},
output: {
path: path.join(buildPath, 'build'),
filename: '[name].js'
},
resolve: {
extensions: ['.js', '.jsx']
},
/* ignore all modules in node_modules folder except webpack/hot/poll */
externals: [nodeExternals({
whitelist: ['webpack/hot/poll?1000']
})],
module: {
rules: [
{
test: /\.(js|jsx)$/,
loader: 'babel-loader',
exclude: /node_modules|dist|build/,
options: {
plugins: [
[
'babel-plugin-react-css-modules',
{
context: postcssPath,
filetypes: {
'.scss': 'postcss-scss'
}
}
]
]
}
},
{
test: /\.local\.(css|scss)$/,
use: [
'css-loader?modules&importLoaders=1&localIdentName=[path]___[name]__[local]___[hash:base64:5]'
]
},
{
test: /\.ejs$/,
loader: 'ejs-loader'
},
{
test: /\.(gif|png|jpg)$/,
loader: 'url-loader'
}
]
},
plugins: [
/* this will clean build folder since using HMR creates new file on every change. Comment out to disable it. */
new WebpackCleanupPlugin({
exclude: ['bundle.js', 'bundle.js.map', 'index.html'],
quiet: true
}),
new StartServerPlugin('bundle.js'),
new webpack.NamedModulesPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
/* We only use it for development to enable live reload */
new HtmlWebpackPlugin({
template: 'ejs-loader!./src/server/views/index.ejs'
}),
new BrowserSyncPlugin({
host: 'localhost',
port: 3003,
ui: {
port: 3002
},
proxy: 'http://localhost:3000/',
codeSync: true,
open: false,
injectChanges: false,
reloadOnRestart: true,
logFileChanges: false,
files: './src/build/bundle.js',
watchOptions: {
awaitWriteFinish: {
/* if browser reloads before webpack updates the bundle file after change on the server, increase the time */
stabilityThreshold: 1000
}
}
},
{
reload: false
})
]
}