-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.js
68 lines (66 loc) · 2.21 KB
/
client.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
import webpack from 'webpack';
import { resolve } from 'path';
import ProgressBarPlugin from 'progress-bar-webpack-plugin';
import { getIfUtils, removeEmpty } from 'webpack-config-utils';
import UglifyJsPlugin from 'uglifyjs-webpack-plugin';
import extractPackageConfig from 'extract-npm-package-config';
import LodashModuleReplacementPlugin from 'lodash-webpack-plugin';
export default (env = {}) => {
const { ifProduction, ifNotProduction } = getIfUtils(env);
return {
name: 'client',
cache: ifNotProduction(),
devtool: ifNotProduction('cheap-module-eval-source-map'),
entry: [resolve('./src/client/index.js')],
target: 'web',
watch: false,
stats: ifProduction('errors-only', 'minimal'),
module: {
rules: [
{
enforce: 'pre',
test: /\.js$/,
use: 'eslint-loader',
include: [resolve('./src/client/'), resolve('./webpack.client.babel.js')],
},
{
test: /\.js$/,
use: 'babel-loader',
include: [
resolve('./src/common/'),
resolve('./src/client/'),
resolve('./webpack.client.babel.js'),
],
},
],
},
output: {
path: resolve('./dist'),
filename: 'client.js',
},
plugins: removeEmpty([
new ProgressBarPlugin(),
new webpack.EnvironmentPlugin(extractPackageConfig(env)),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(ifProduction('production', process.env.NODE_ENV)),
}),
ifProduction(
new UglifyJsPlugin({
uglifyOptions: {
ie8: false,
warnings: false,
compress: true,
},
sourceMap: false,
})
),
ifProduction(new webpack.optimize.AggressiveMergingPlugin()), // merge chunks
ifProduction(new webpack.optimize.ModuleConcatenationPlugin()), // scope hoisting
ifProduction(new webpack.HashedModuleIdsPlugin()), // scope hoisting
ifProduction(new LodashModuleReplacementPlugin()),
ifNotProduction(new webpack.HotModuleReplacementPlugin()),
ifNotProduction(new webpack.NamedModulesPlugin()),
ifNotProduction(new webpack.NoEmitOnErrorsPlugin()),
]),
};
};