1 | const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
2 | const HtmlWebpackPlugin = require('html-webpack-plugin');
|
3 | const path = require('path');
|
4 | const Stylish = require('webpack-stylish');
|
5 | const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
|
6 | const webpack = require('webpack');
|
7 |
|
8 | module.exports = function(env, argv) {
|
9 | const analyzer = env.analyzer;
|
10 | const production = env.production;
|
11 | const tag = env.tag;
|
12 | const workingDir = env.workingDir;
|
13 | let entry = {
|
14 | [`${tag}.bundled`]: path.resolve('dist', `${tag}.js`),
|
15 | };
|
16 | let plugins = [
|
17 | new UglifyJsPlugin({
|
18 | include: /\.min\.js$/,
|
19 | parallel: true,
|
20 | sourceMap: true,
|
21 | uglifyOptions: {
|
22 | ecma: 6,
|
23 | },
|
24 | }),
|
25 | new HtmlWebpackPlugin({
|
26 | filename: 'index.html',
|
27 | template: 'index.html',
|
28 | chunks: [`${tag}.bundled`],
|
29 | }),
|
30 | new Stylish(),
|
31 | ];
|
32 |
|
33 | if (analyzer) {
|
34 | plugins.push(new BundleAnalyzerPlugin());
|
35 | }
|
36 |
|
37 | if (production) {
|
38 | entry[`${tag}.min`] = path.resolve('dist', `${tag}.js`);
|
39 | } else {
|
40 | plugins.push(new webpack.HotModuleReplacementPlugin());
|
41 | }
|
42 |
|
43 | return {
|
44 | mode: production ? 'production' : 'development',
|
45 | stats: 'none',
|
46 | context: workingDir,
|
47 | devServer: {
|
48 | contentBase: path.resolve(workingDir, '.'),
|
49 | hot: !production,
|
50 | },
|
51 | devtool: production ? 'source-map' : 'eval',
|
52 | entry: entry,
|
53 | output: {
|
54 | filename: '[name].js',
|
55 | path: path.resolve(workingDir, 'dist'),
|
56 | },
|
57 | plugins: plugins,
|
58 | resolve: {
|
59 | extensions: ['.js'],
|
60 | },
|
61 | };
|
62 | }
|