Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9aa71e1

Browse files
committed
update
1 parent 7d48c53 commit 9aa71e1

File tree

5 files changed

+1830
-759
lines changed

5 files changed

+1830
-759
lines changed

‎package.json‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "index.js",
66
"scripts": {
77
"start": "node server.js --max_old_space_size=4096",
8-
"build": "webpack -p --config webpack.production.config.js",
8+
"build": "webpack --config webpack.production.config.js",
99
"dist": "set NODE_ENV=production&& node server.js",
1010
"distmac": "export NODE_ENV=production&& node server.js",
1111
"prettier": "prettier --write \"{src,mock}/**/*.{js,css,less}\"",
@@ -50,7 +50,7 @@
5050
"@babel/plugin-transform-runtime": "^7.14.3",
5151
"@babel/preset-env": "^7.14.2",
5252
"@babel/preset-react": "^7.13.13",
53-
"@babel/runtime": "^7.0.0",
53+
"@babel/runtime": "^7.14.0",
5454
"antd-dayjs-webpack-plugin": "^1.0.6",
5555
"autoprefixer": "^10.2.6",
5656
"babel-eslint": "^10.1.0",
@@ -60,12 +60,14 @@
6060
"clean-webpack-plugin": "^3.0.0",
6161
"copy-webpack-plugin": "^9.0.0",
6262
"css-loader": "^5.2.6",
63+
"css-minimizer-webpack-plugin": "^3.0.0",
6364
"eslint": "^7.27.0",
6465
"eslint-loader": "^4.0.2",
6566
"eslint-plugin-prettier": "^3.4.0",
6667
"eslint-plugin-react": "^7.23.2",
6768
"eslint-plugin-react-hooks": "^4.2.0",
6869
"express": "^4.17.1",
70+
"favicons": "^6.2.2",
6971
"favicons-webpack-plugin": "5.0.2",
7072
"file-loader": "^6.2.0",
7173
"happypack": "^5.0.1",
@@ -74,19 +76,19 @@
7476
"less-loader": "^9.0.0",
7577
"mini-css-extract-plugin": "^1.6.0",
7678
"mockjs": "^1.1.0",
77-
"optimize-css-assets-webpack-plugin": "^6.0.0",
79+
"postcss": "^8.3.0",
7880
"postcss-loader": "^5.3.0",
7981
"prettier": "2.3.0",
8082
"source-map-loader": "^3.0.0",
8183
"style-loader": "2.0.0",
82-
"sw-precache-webpack-plugin": "^1.0.0",
8384
"terser-webpack-plugin": "^5.1.2",
8485
"url-loader": "^4.1.1",
8586
"webpack": "^5.37.1",
8687
"webpack-cli": "^4.7.0",
8788
"webpack-dev-middleware": "^4.3.0",
8889
"webpack-hot-middleware": "^2.25.0",
8990
"webpackbar": "^4.0.0",
91+
"workbox-webpack-plugin": "^6.1.5",
9092
"xml-loader": "^1.2.1"
9193
},
9294
"browserslist": [

‎src/a_component/Footer/index.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ export default class Com extends React.PureComponent {
1414
return (
1515
<Footer className={`footer ${this.props.className}`}>
1616
© 2018-{new Date().getFullYear()}{" "}
17-
<a href="https://blog.isluo.com" target="_blank" rel="noopener noreferrer">
17+
<a
18+
href="https://blog.isluo.com"
19+
target="_blank"
20+
rel="noopener noreferrer"
21+
>
1822
blog.isluo.com
1923
</a>
2024
, Inc.

‎src/a_container/home/index.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ export default class HomePageContainer extends React.Component {
2525
<div className="box">
2626
<img src={ImgLogo} />
2727
<div className="title">React-admin</div>
28-
<div className="info">标准React+Redux分层结构,react17、router4、antd4、webpack5、ES6+</div>
28+
<div className="info">
29+
标准React+Redux分层结构,react17、router4、antd4、webpack5、ES6+
30+
</div>
2931
<div className="info">动态菜单配置,权限精确到按钮</div>
3032
</div>
3133
</div>

‎webpack.production.config.js‎

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
const path = require("path");
44
const webpack = require("webpack"); // webpack核心
55
const MiniCssExtractPlugin = require("mini-css-extract-plugin"); // 为了单独打包css
6+
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin"); // 对CSS进行压缩
67
const HtmlWebpackPlugin = require("html-webpack-plugin"); // 生成html
78
const AntdDayjsWebpackPlugin = require("antd-dayjs-webpack-plugin");
89
const { CleanWebpackPlugin } = require("clean-webpack-plugin"); // 每次打包前清除旧的build文件夹
10+
const WorkboxPlugin = require("workbox-webpack-plugin"); // 用于生成PWA servers-worker.js
911
const CopyPlugin = require("copy-webpack-plugin"); // 用于直接复制public中的文件到打包的最终文件夹中
10-
const SWPrecacheWebpackPlugin = require("sw-precache-webpack-plugin"); // 生成一个server-worker用于缓存
1112
const FaviconsWebpackPlugin = require("favicons-webpack-plugin"); // 自动生成各尺寸的favicon图标
1213
const TerserPlugin = require("terser-webpack-plugin"); // 优化js
13-
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin"); // 压缩CSS
1414
const webpackbar = require("webpackbar"); // 进度条
1515
/**
1616
* 基础路径
@@ -30,10 +30,11 @@ module.exports = {
3030
chunkFilename: "dist/[name].[chunkhash:8].chunk.js",
3131
},
3232
stats: {
33-
warningsFilter: warning => /Conflictingorder/gm.test(warning), // 不输出一些警告,多为因CSS引入顺序不同导致的警告
33+
// warningsFilter: warning => /Conflicting order/gm.test(warning), // 不输出一些警告,多为因CSS引入顺序不同导致的警告
3434
children: false, // 不输出子模块的打包信息
3535
},
3636
optimization: {
37+
minimize: true,
3738
minimizer: [
3839
new TerserPlugin({
3940
parallel: true, // 多线程并行构建
@@ -47,7 +48,7 @@ module.exports = {
4748
},
4849
},
4950
}),
50-
new OptimizeCSSAssetsPlugin({}),
51+
new CssMinimizerPlugin(),
5152
],
5253
splitChunks: {
5354
chunks: "all",
@@ -69,7 +70,7 @@ module.exports = {
6970
{
7071
// .less 解析
7172
test: /\.less$/,
72-
use: [MiniCssExtractPlugin.loader, "css-loader", "postcss-loader", { loader: "less-loader", options: { lessOptions:{javascriptEnabled: true} } }],
73+
use: [MiniCssExtractPlugin.loader, "css-loader", "postcss-loader", { loader: "less-loader", options: { lessOptions:{javascriptEnabled: true} } }],
7374
},
7475
{
7576
// 文件解析
@@ -134,26 +135,7 @@ module.exports = {
134135
* **/
135136
new MiniCssExtractPlugin({
136137
filename: "dist/[name].[chunkhash:8].css", // 生成的文件名
137-
}),
138-
/**
139-
* 生成一个server-work用于缓存资源(PWA)
140-
* */
141-
new SWPrecacheWebpackPlugin({
142-
dontCacheBustUrlsMatching: /\.\w{8}\./,
143-
filename: "service-worker.js",
144-
logger(message) {
145-
if (message.indexOf("Total precache size is") === 0) {
146-
return;
147-
}
148-
if (message.indexOf("Skipping static resource") === 0) {
149-
return;
150-
}
151-
console.log(message);
152-
},
153-
minify: true, // 压缩
154-
navigateFallback: PUBLIC_PATH, // 遇到不存在的URL时,跳转到主页
155-
navigateFallbackWhitelist: [/^(?!\/__).*/], // 忽略从/__开始的网址,参考 https://github.com/facebookincubator/create-react-app/issues/2237#issuecomment-302693219
156-
staticFileGlobsIgnorePatterns: [/\.map$/, /asset-manifest\.json$/, /\.cache$/], // 不缓存sourcemaps,它们太大了
138+
ignoreOrder: true, // 忽略因CSS文件引入顺序不一致而抛出的警告信息,多为antd内部css引起
157139
}),
158140
// 拷贝public中的文件到最终打包文件夹里
159141
new CopyPlugin({
@@ -176,6 +158,14 @@ module.exports = {
176158
template: "./public/index.html", // html模板路径
177159
hash: false, // 防止缓存,在引入的文件后面加hash (PWA就是要缓存,这里设置为false)
178160
inject: true, // 是否将js放在body的末尾
161+
// 正式环境,把注册service-worker的代码加入到index.html中
162+
registerServiceWorker: `<script>
163+
if ("serviceWorker" in navigator) {
164+
window.addEventListener("load", () => {
165+
navigator.serviceWorker.register("./service-worker.js");
166+
});
167+
}
168+
</script>`,
179169
}),
180170
/**
181171
* 自动生成各种类型的favicon图标
@@ -211,6 +201,13 @@ module.exports = {
211201
},
212202
},
213203
}),
204+
/**
205+
* PWA - 自动生成server-worker.js
206+
* https://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-webpack-plugin.GenerateSW?hl=en
207+
* */
208+
new WorkboxPlugin.GenerateSW({
209+
skipWaiting: true,
210+
}),
214211
],
215212
resolve: {
216213
extensions: [".js", ".jsx", ".less", ".css", ".wasm"], // 后缀名自动补全

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /