1 | const path = require('path');
|
2 |
|
3 | const autoprefixer = require('autoprefixer');
|
4 | const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
|
5 | const webpack = require('webpack');
|
6 | const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
7 | const merge = require('webpack-merge');
|
8 | const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
9 | const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
|
10 | const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
|
11 |
|
12 | const base = require('./base');
|
13 |
|
14 | module.exports = arg =>
|
15 | merge(base(arg), {
|
16 | bail: true,
|
17 |
|
18 | mode: 'production',
|
19 |
|
20 | module: {
|
21 | rules: [
|
22 | {
|
23 | test: /\.jsx?$/,
|
24 | include: arg.options.compileNodeModules
|
25 | ? [path.resolve(arg.context, './src'), path.resolve(arg.context, './node-modules')]
|
26 | : path.resolve(arg.context, './src'),
|
27 | loader: 'babel-loader',
|
28 | options: arg.options.babelrc
|
29 | ? { babelrc: true }
|
30 | : {
|
31 | babelrc: false,
|
32 | presets: [
|
33 | [
|
34 | require.resolve('babel-preset-env'),
|
35 | {
|
36 | targets: {
|
37 | browsers: arg.options.browsers,
|
38 | },
|
39 | modules: false,
|
40 | spec: true,
|
41 | useBuiltIns: true,
|
42 | },
|
43 | ],
|
44 | require.resolve('babel-preset-stage-2'),
|
45 | require.resolve('babel-preset-react'),
|
46 | ],
|
47 | plugins: [require.resolve('babel-plugin-transform-decorators-legacy')],
|
48 | },
|
49 | },
|
50 | {
|
51 | test: /\.css$/,
|
52 | oneOf: [
|
53 | {
|
54 | exclude: /node_modules/,
|
55 | use: [
|
56 | MiniCssExtractPlugin.loader,
|
57 | {
|
58 | loader: 'css-loader',
|
59 | options: { modules: arg.options.cssModules, camelCase: 'only', importLoaders: 1 },
|
60 | },
|
61 | {
|
62 | loader: 'postcss-loader',
|
63 | options: {
|
64 | ident: 'postcss',
|
65 | plugins: () => [autoprefixer({ browsers: arg.options.browsers })],
|
66 | },
|
67 | },
|
68 | ],
|
69 | },
|
70 | {
|
71 | include: /node_modules/,
|
72 | use: [
|
73 | MiniCssExtractPlugin.loader,
|
74 | {
|
75 | loader: 'css-loader',
|
76 | options: { importLoaders: 1 },
|
77 | },
|
78 | {
|
79 | loader: 'postcss-loader',
|
80 | options: {
|
81 | ident: 'postcss',
|
82 | plugins: () => [autoprefixer({ browsers: arg.options.browsers })],
|
83 | },
|
84 | },
|
85 | ],
|
86 | },
|
87 | ],
|
88 | },
|
89 | {
|
90 | test: /\.less$/,
|
91 | oneOf: [
|
92 | {
|
93 | exclude: /node_modules/,
|
94 | use: [
|
95 | MiniCssExtractPlugin.loader,
|
96 | {
|
97 | loader: 'css-loader',
|
98 | options: { modules: arg.options.cssModules, camelCase: 'only', importLoaders: 1 },
|
99 | },
|
100 | {
|
101 | loader: 'postcss-loader',
|
102 | options: {
|
103 | ident: 'postcss',
|
104 | plugins: () => [autoprefixer({ browsers: arg.options.browsers })],
|
105 | },
|
106 | },
|
107 | 'less-loader',
|
108 | ],
|
109 | },
|
110 | {
|
111 | include: /node_modules/,
|
112 | use: [
|
113 | MiniCssExtractPlugin.loader,
|
114 | {
|
115 | loader: 'css-loader',
|
116 | options: { importLoaders: 1 },
|
117 | },
|
118 | {
|
119 | loader: 'postcss-loader',
|
120 | options: {
|
121 | ident: 'postcss',
|
122 | plugins: () => [autoprefixer({ browsers: arg.options.browsers })],
|
123 | },
|
124 | },
|
125 | 'less-loader',
|
126 | ],
|
127 | },
|
128 | ],
|
129 | },
|
130 | ],
|
131 | },
|
132 |
|
133 | optimization: {
|
134 | minimizer: [
|
135 | new UglifyJsPlugin({
|
136 | cache: true,
|
137 | parallel: true,
|
138 | sourceMap: true,
|
139 | uglifyOptions: {
|
140 | ie8: arg.options.supportIE8,
|
141 | warnings: true,
|
142 | compress: {
|
143 | warnings: false,
|
144 |
|
145 |
|
146 |
|
147 |
|
148 | comparisons: false,
|
149 | },
|
150 | mangle: {
|
151 | safari10: true,
|
152 | },
|
153 | output: {
|
154 | comments: false,
|
155 |
|
156 |
|
157 | ascii_only: true,
|
158 | },
|
159 | },
|
160 | }),
|
161 | new OptimizeCSSAssetsPlugin({}),
|
162 | ],
|
163 | },
|
164 |
|
165 | plugins: [
|
166 | new BundleAnalyzerPlugin({
|
167 | analyzerMode: 'static',
|
168 | logLevel: 'warn',
|
169 | reportFilename: 'bundle-report.html',
|
170 | }),
|
171 | new CaseSensitivePathsPlugin(),
|
172 | new MiniCssExtractPlugin(),
|
173 | new webpack.DefinePlugin({
|
174 | __ENV__: JSON.stringify('prod'),
|
175 | }),
|
176 | new webpack.ProgressPlugin(),
|
177 | arg.options.profile && new webpack.debug.ProfilingPlugin(),
|
178 | ].filter(Boolean),
|
179 | });
|