forked from whilelucky/pwa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.server.js
89 lines (80 loc) · 2.64 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
/* eslint-disable max-len */
const path = require('path');
const webpack = require('webpack');
const nodeExternals = require('webpack-node-externals');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const __PWA_ENV__ = process.env.PWA_ENV;
const __PWA_PUBLIC_PATH__ = process.env.PWA_PUBLIC_PATH;
const isProd = process.env.NODE_ENV === 'production';
module.exports = {
entry: './server/index.js',
target: 'node',
externals: [
nodeExternals({ whitelist: [/\.css$/] }),
/assetsManifest.json/,
],
output: {
path: path.resolve('./build/server'),
publicPath: __PWA_PUBLIC_PATH__,
filename: 'index.js',
chunkFilename: '[name].js',
libraryTarget: 'commonjs2',
},
resolve: {
alias: {
react: 'preact-compat',
'react-dom': 'preact-compat',
},
},
module: {
rules: isProd ? [
{ test: /\.js$/, exclude: /node_modules/, use: ['babel-loader'] },
{ test: /\.css$/, use: ['css-loader/locals', 'postcss-loader'] },
{ test: /\.(gif|png|jpe?g|svg|ico)$/i, use: [{ loader: 'file-loader', options: { name: 'images/[name].[hash:8].[ext]' } }] },
{ test: /\.(woff(2)?|ttf|otf|eot)(\?[a-z0-9=&.]+)?$/, use: [{ loader: 'url-loader', options: { limit: 1000, name: 'fonts/[name].[hash:8].[ext]' } }] },
] : [
{ test: /\.js$/, exclude: /node_modules/, use: ['babel-loader'] },
{ test: /\.css$/, use: ['css-loader/locals', 'postcss-loader'] },
{ test: /\.(gif|png|jpe?g|svg|ico)$/i, use: [{ loader: 'file-loader', options: { name: 'images/[name].[ext]' } }] },
{ test: /\.(woff(2)?|ttf|otf|eot)(\?[a-z0-9=&.]+)?$/, use: [{ loader: 'url-loader', options: { limit: 1000, name: 'fonts/[name].[ext]' } }] },
],
},
plugins: [
new webpack.NoEmitOnErrorsPlugin(),
new CleanWebpackPlugin(['./build/server']),
new webpack.DefinePlugin({
'process.env.NODE_ENV': isProd ? '"production"' : '"development"',
__BROWSER__: false,
__PWA_ENV__: JSON.stringify(__PWA_ENV__),
__LOCAL__: __PWA_ENV__ === 'local',
}),
new webpack.optimize.CommonsChunkPlugin({
children: true,
minChunks: 2,
}),
...(isProd ? [
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false,
}),
new webpack.HashedModuleIdsPlugin(),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
compress: {
screw_ie8: true,
warnings: false,
},
mangle: {
screw_ie8: true,
},
output: {
comments: false,
screw_ie8: true,
},
}),
] : [
new webpack.NamedModulesPlugin(),
]),
],
devtool: 'source-map',
};