|
1 | 1 | const path = require("path");
|
2 | 2 | const HtmlWebpackPlugin = require("html-webpack-plugin");
|
3 | 3 | const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
| 4 | +const CssMinimizerPlugin = require("css-minimizer-webpack-plugin"); |
| 5 | +const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; |
| 6 | +const CopyWebpackPlugin = require('copy-webpack-plugin'); |
| 7 | +const CleanWebPackPlugin = require('clean-webpack-plugin').CleanWebpackPlugin; |
| 8 | +const UglifyParallelPlugin = require('webpack-parallel-uglify-plugin'); |
4 | 9 |
|
5 | 10 | module.exports = {
|
6 | 11 | entry: {
|
7 |
| - main: "./src/main.ts", |
| 12 | + seaper: "./src/main.ts", |
8 | 13 | },
|
9 | 14 | output: {
|
10 |
| - filename: "[name].js", |
| 15 | + filename: "js/[name].bundle.js", |
11 | 16 | path: path.join(__dirname, "../dist"),
|
12 | 17 | },
|
13 | 18 | module: {
|
@@ -35,12 +40,64 @@ module.exports = {
|
35 | 40 | resolve: {
|
36 | 41 | extensions: [".tsx", ".ts", ".js"],
|
37 | 42 | },
|
| 43 | + optimization: { |
| 44 | + splitChunks: { |
| 45 | + chunks: 'all', |
| 46 | + cacheGroups: { |
| 47 | + rc: { |
| 48 | + name: "rc", |
| 49 | + test: (module) => (/rc-/.test(module.context)), |
| 50 | + priority: 4 |
| 51 | + }, |
| 52 | + react: { |
| 53 | + name: "react", |
| 54 | + test: (module) => (/react/.test(module.context) || /redux/.test(module.context) |
| 55 | + || /classnames/.test(module.context) || /prop-types/.test(module.context)), |
| 56 | + priority: 3 |
| 57 | + }, |
| 58 | + antd: { |
| 59 | + name: "antd", |
| 60 | + test: (module) => (/antd/.test(module.context) || /ant-design/.test(module.context)), |
| 61 | + priority: 2 |
| 62 | + }, |
| 63 | + default: { |
| 64 | + name: "other", |
| 65 | + test: (module) => (/node_modules/.test(module.context)), |
| 66 | + priority: 1 |
| 67 | + } |
| 68 | + } |
| 69 | + }, |
| 70 | + runtimeChunk: { |
| 71 | + name: entrypoint => `rt-${entrypoint.name}` |
| 72 | + }, |
| 73 | + minimizer:[ |
| 74 | + new CssMinimizerPlugin(), |
| 75 | + ] |
| 76 | + }, |
38 | 77 | plugins: [
|
39 | 78 | new HtmlWebpackPlugin({
|
40 |
| - template: "./public/index.html", |
| 79 | + template: "./index.html", |
| 80 | + filename: './index.html', |
| 81 | + chunks: "all" |
| 82 | + }), |
| 83 | + new MiniCssExtractPlugin(), |
| 84 | + new BundleAnalyzerPlugin(), |
| 85 | + new CopyWebpackPlugin({ |
| 86 | + patterns: [ |
| 87 | + { |
| 88 | + from: path.resolve(__dirname, '../public'), |
| 89 | + to: path.resolve(__dirname, '../dist'), |
| 90 | + } |
| 91 | + ] |
41 | 92 | }),
|
42 |
| - new MiniCssExtractPlugin({ |
43 |
| - filename: "main.css" |
| 93 | + new CleanWebPackPlugin(), |
| 94 | + new UglifyParallelPlugin({ |
| 95 | + uglifyJS: { |
| 96 | + output: { |
| 97 | + beautify: false, |
| 98 | + comments: false |
| 99 | + } |
| 100 | + } |
44 | 101 | })
|
45 | 102 | ],
|
46 | 103 | mode: "production",
|
|
0 commit comments