Skip to content

Commit 77b4fd3

Browse files
author
GongJS
committed
fix
1 parent 250291f commit 77b4fd3

File tree

8 files changed

+1248
-92
lines changed

8 files changed

+1248
-92
lines changed

.DS_Store

8 KB
Binary file not shown.

lib/.DS_Store

0 Bytes
Binary file not shown.

lib/components/.DS_Store

0 Bytes
Binary file not shown.

package-lock.json

Lines changed: 116 additions & 71 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"html-webpack-plugin": "^3.2.0",
5353
"jest": "^24.7.1",
5454
"jest-junit": "^6.3.0",
55+
"mini-css-extract-plugin": "^0.9.0",
5556
"node-sass": "^4.11.0",
5657
"prism-react-renderer": "^0.1.6",
5758
"prop-types": "^15.7.2",
@@ -70,12 +71,14 @@
7071
"dependencies": {
7172
"@types/react-onclickoutside": "^6.7.3",
7273
"@types/react-transition-group": "^4.2.2",
74+
"optimize-css-assets-webpack-plugin": "^5.0.3",
7375
"punycode": "^2.1.1",
7476
"react": "^16.8.6",
7577
"react-dom": "^16.8.6",
7678
"react-markdown": "^4.1.0",
7779
"react-router-dom": "^5.0.0",
78-
"react-transition-group": "^4.2.2"
80+
"react-transition-group": "^4.2.2",
81+
"terser-webpack-plugin": "^2.3.5"
7982
},
8083
"config": {
8184
"commitizen": {

webpack.config.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ const path = require('path');
22
const {
33
CheckerPlugin
44
} = require('awesome-typescript-loader')
5+
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
6+
const devMode = process.env.NODE_ENV !== 'production'
57

68
function resolve(dir) {
79
return path.join(__dirname, '', dir)
@@ -28,17 +30,23 @@ module.exports = {
2830
use: ['awesome-typescript-loader']
2931
},
3032
{
31-
test: /\.css$/,
32-
use: ['style-loader', 'css-loader']
33-
},
34-
{
35-
test: /\.s[ac]ss$/,
36-
use: ['style-loader', 'css-loader', 'sass-loader']
33+
test: /\.(sa|sc|c)ss$/, // 可以打包后缀为sass/scss/css的文件
34+
use: [
35+
{
36+
loader: MiniCssExtractPlugin.loader,
37+
options: {
38+
publicPath: './',
39+
hmr: devMode, // 仅dev环境启用HMR功能
40+
},
41+
},
42+
'css-loader',
43+
'sass-loader'
44+
],
3745
},
3846
{
3947
test: /\.svg$/,
4048
loader: 'svg-sprite-loader'
41-
},
49+
},
4250
{
4351
test: /\.(png|jpg|gif|jpeg)$/,
4452
use: {
@@ -49,6 +57,12 @@ module.exports = {
4957
]
5058
},
5159
plugins: [
52-
new CheckerPlugin()
60+
new CheckerPlugin(),
61+
new MiniCssExtractPlugin({
62+
// 这里的配置和webpackOptions.output中的配置相似
63+
// 即可以通过在名字前加路径,来决定打包后的文件存在的路径
64+
filename: devMode ? 'css/[name].css' : 'css/[name].[hash].css',
65+
chunkFilename: devMode ? 'css/[id].css' : 'css/[id].[hash].css',
66+
})
5367
]
5468
}

webpack.config.prod.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
const baseConfig = require('./webpack.config');
2+
const TerserJSPlugin = require('terser-webpack-plugin');
3+
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
24

35
module.exports = Object.assign({}, baseConfig, {
46
mode: 'production',
7+
optimization: {
8+
minimizer: [new TerserJSPlugin({}), new OptimizeCSSAssetsPlugin({})],
9+
splitChunks: {
10+
cacheGroups: {
11+
styles: {
12+
name: 'styles',
13+
test: /\.css$/,
14+
chunks: 'all',
15+
enforce: true,
16+
},
17+
}
18+
},
19+
},
520
externals: {
621
react: {
722
commonjs: 'react',

0 commit comments

Comments
 (0)