|
1 | 1 | const HtmlWebpackPlugin = require('html-webpack-plugin') |
2 | 2 | const path = require('path') |
3 | 3 |
|
4 | | -module.exports = { |
5 | | - devtool: 'inline-source-map', |
6 | | - entry: path.join(__dirname, 'src', 'index.tsx'), |
7 | | - output: { |
8 | | - publicPath: '/', |
9 | | - path: path.join(__dirname, 'dist'), |
10 | | - filename: 'bundle.js', |
11 | | - }, |
12 | | - optimization: { |
13 | | - splitChunks: { |
14 | | - chunks: 'all', |
| 4 | +module.exports = (env, args) => { |
| 5 | + const isProduction = args.mode === 'production' |
| 6 | + return { |
| 7 | + devtool: isProduction ? 'source-map' : 'inline-source-map', |
| 8 | + entry: path.join(__dirname, 'src', 'index.tsx'), |
| 9 | + output: { |
| 10 | + publicPath: '/', |
| 11 | + path: path.join(__dirname, 'dist'), |
| 12 | + filename: 'bundle.js', |
15 | 13 | }, |
16 | | - }, |
17 | | - devServer: { |
18 | | - proxy: { |
19 | | - '/backend': 'http://localhost:5000', |
20 | | - }, |
21 | | - historyApiFallback: true, |
22 | | - }, |
23 | | - module: { |
24 | | - rules: [ |
| 14 | + optimization: Object.assign( |
25 | 15 | { |
26 | | - test: /\.md/, |
27 | | - use: 'raw-loader', |
| 16 | + splitChunks: { |
| 17 | + chunks: 'all', |
| 18 | + }, |
28 | 19 | }, |
29 | | - { |
30 | | - test: /\.(png|woff2)$/, |
31 | | - use: [ |
32 | | - { |
33 | | - loader: 'url-loader', |
| 20 | + isProduction && { |
| 21 | + minimizer: [ |
| 22 | + (compiler) => { |
| 23 | + const TerserPlugin = require('terser-webpack-plugin') |
| 24 | + new TerserPlugin({ |
| 25 | + cache: true, |
| 26 | + parallel: true, |
| 27 | + sourceMap: true, |
| 28 | + terserOptions: { |
| 29 | + safari10: true, |
| 30 | + }, |
| 31 | + }).apply(compiler) |
34 | 32 | }, |
35 | 33 | ], |
| 34 | + } |
| 35 | + ), |
| 36 | + devServer: { |
| 37 | + proxy: { |
| 38 | + '/backend': 'http://localhost:5000', |
36 | 39 | }, |
37 | | - { |
38 | | - test: /\.tsx?$/, |
39 | | - loader: 'ts-loader', |
40 | | - include: path.join(__dirname, 'src'), |
41 | | - options: { |
42 | | - allowTsInNodeModules: true, |
| 40 | + historyApiFallback: true, |
| 41 | + }, |
| 42 | + module: { |
| 43 | + rules: [ |
| 44 | + { |
| 45 | + test: /\.md/, |
| 46 | + use: 'raw-loader', |
43 | 47 | }, |
44 | | - }, |
| 48 | + { |
| 49 | + test: /\.(png|woff2)$/, |
| 50 | + use: [ |
| 51 | + { |
| 52 | + loader: 'url-loader', |
| 53 | + }, |
| 54 | + ], |
| 55 | + }, |
| 56 | + { |
| 57 | + test: /\.tsx?$/, |
| 58 | + loader: 'ts-loader', |
| 59 | + include: path.join(__dirname, 'src'), |
| 60 | + options: { |
| 61 | + allowTsInNodeModules: true, |
| 62 | + }, |
| 63 | + }, |
| 64 | + ], |
| 65 | + }, |
| 66 | + resolve: { |
| 67 | + extensions: ['.tsx', '.ts', '.js'], |
| 68 | + }, |
| 69 | + plugins: [ |
| 70 | + new HtmlWebpackPlugin({ |
| 71 | + template: path.join(__dirname, 'backend', 'index.html'), |
| 72 | + }), |
45 | 73 | ], |
46 | | - }, |
47 | | - resolve: { |
48 | | - extensions: ['.tsx', '.ts', '.js'], |
49 | | - }, |
50 | | - plugins: [ |
51 | | - new HtmlWebpackPlugin({ |
52 | | - template: path.join(__dirname, 'backend', 'index.html'), |
53 | | - }), |
54 | | - ], |
| 74 | + } |
55 | 75 | } |
0 commit comments