From ab4cc6a5a8d6f99921597720d184cc3efe13b100 Mon Sep 17 00:00:00 2001 From: qlin Date: Fri, 6 Jan 2023 17:44:30 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20webpack=20=E7=BC=93=E5=AD=98=E4=B8=8D?= =?UTF-8?q?=E6=96=AD=E5=8F=A0=E5=8A=A0=20(#167)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/fes-builder-webpack/package.json | 138 +++++++++--------- .../src/plugins/commands/dev/index.js | 20 +++ packages/fes-template/.fes.js | 57 ++++---- yarn.lock | 18 +++ 4 files changed, 136 insertions(+), 97 deletions(-) diff --git a/packages/fes-builder-webpack/package.json b/packages/fes-builder-webpack/package.json index c04ff76a..50b47cf4 100644 --- a/packages/fes-builder-webpack/package.json +++ b/packages/fes-builder-webpack/package.json @@ -1,69 +1,71 @@ { - "name": "@fesjs/builder-webpack", - "version": "3.0.0-rc.2", - "description": "@fesjs/builder-webpack", - "main": "lib/index.js", - "types": "types.d.ts", - "files": [ - "lib", - "types.d.ts" - ], - "repository": { - "type": "git", - "url": "git+https://github.com/WeBankFinTech/fes.js.git", - "directory": "packages/fes-builder-webpack" - }, - "keywords": [ - "fes" - ], - "author": "qlin", - "license": "MIT", - "bugs": { - "url": "https://github.com/WeBankFinTech/fes.js/issues" - }, - "homepage": "https://github.com/WeBankFinTech/fes.js#readme", - "publishConfig": { - "access": "public" - }, - "dependencies": { - "@babel/core": "^7.16.0", - "@babel/plugin-proposal-do-expressions": "^7.16.0", - "@babel/plugin-proposal-export-default-from": "^7.16.0", - "@babel/plugin-proposal-function-bind": "^7.16.0", - "@babel/plugin-proposal-pipeline-operator": "^7.16.0", - "@babel/plugin-transform-runtime": "^7.16.4", - "@babel/preset-env": "^7.16.4", - "@babel/preset-typescript": "^7.15.0", - "@fesjs/utils": "3.0.0-rc.2", - "@vue/babel-plugin-jsx": "^1.1.1", - "autoprefixer": "^10.2.4", - "babel-loader": "^8.2.2", - "babel-plugin-import": "1.13.3", - "cli-highlight": "^2.1.4", - "cliui": "7.0.4", - "connect-history-api-fallback": "^1.6.0", - "copy-webpack-plugin": "^7.0.0", - "css-loader": "^5.0.1", - "css-minimizer-webpack-plugin": "^3.0.0", - "html-webpack-plugin": "^5.0.0", - "html-webpack-tags-plugin": "^3.0.0", - "less": "3.9.0", - "less-loader": "^8.0.0", - "mini-css-extract-plugin": "^1.3.5", - "postcss": "8.3.0", - "postcss-flexbugs-fixes": "^5.0.2", - "postcss-loader": "^4.2.0", - "postcss-safe-parser": "^6.0.0", - "style-loader": "^2.0.0", - "vue-loader": "^16.1.2", - "webpack": "^5.69.0", - "webpack-bundle-analyzer": "^4.4.0", - "webpack-chain": "^6.5.1", - "webpack-dev-server": "^4.8.1", - "webpackbar": "^5.0.2" - }, - "peerDependencies": { - "@fesjs/fes": "3.0.0-rc.2", - "core-js": "^3.27.0" - } -} \ No newline at end of file + "name": "@fesjs/builder-webpack", + "version": "3.0.0-rc.2", + "description": "@fesjs/builder-webpack", + "main": "lib/index.js", + "types": "types.d.ts", + "files": [ + "lib", + "types.d.ts" + ], + "repository": { + "type": "git", + "url": "git+https://github.com/WeBankFinTech/fes.js.git", + "directory": "packages/fes-builder-webpack" + }, + "keywords": [ + "fes" + ], + "author": "qlin", + "license": "MIT", + "bugs": { + "url": "https://github.com/WeBankFinTech/fes.js/issues" + }, + "homepage": "https://github.com/WeBankFinTech/fes.js#readme", + "publishConfig": { + "access": "public" + }, + "dependencies": { + "@babel/core": "^7.16.0", + "@babel/plugin-proposal-do-expressions": "^7.16.0", + "@babel/plugin-proposal-export-default-from": "^7.16.0", + "@babel/plugin-proposal-function-bind": "^7.16.0", + "@babel/plugin-proposal-pipeline-operator": "^7.16.0", + "@babel/plugin-transform-runtime": "^7.16.4", + "@babel/preset-env": "^7.16.4", + "@babel/preset-typescript": "^7.15.0", + "@fesjs/utils": "3.0.0-rc.2", + "@vue/babel-plugin-jsx": "^1.1.1", + "autoprefixer": "^10.2.4", + "babel-loader": "^8.2.2", + "babel-plugin-import": "1.13.3", + "cli-highlight": "^2.1.4", + "cliui": "7.0.4", + "connect-history-api-fallback": "^1.6.0", + "copy-webpack-plugin": "^7.0.0", + "css-loader": "^5.0.1", + "css-minimizer-webpack-plugin": "^3.0.0", + "fs-extra": "^10.0.0", + "html-webpack-plugin": "^5.0.0", + "html-webpack-tags-plugin": "^3.0.0", + "get-folder-size": "^2.0.1", + "less": "3.9.0", + "less-loader": "^8.0.0", + "mini-css-extract-plugin": "^1.3.5", + "postcss": "8.3.0", + "postcss-flexbugs-fixes": "^5.0.2", + "postcss-loader": "^4.2.0", + "postcss-safe-parser": "^6.0.0", + "style-loader": "^2.0.0", + "vue-loader": "^16.1.2", + "webpack": "^5.69.0", + "webpack-bundle-analyzer": "^4.4.0", + "webpack-chain": "^6.5.1", + "webpack-dev-server": "^4.8.1", + "webpackbar": "^5.0.2" + }, + "peerDependencies": { + "@fesjs/fes": "3.0.0-rc.2", + "core-js": "^3.27.0" + } +} diff --git a/packages/fes-builder-webpack/src/plugins/commands/dev/index.js b/packages/fes-builder-webpack/src/plugins/commands/dev/index.js index 17efda9f..b3346b5e 100644 --- a/packages/fes-builder-webpack/src/plugins/commands/dev/index.js +++ b/packages/fes-builder-webpack/src/plugins/commands/dev/index.js @@ -1,3 +1,22 @@ +const path = require('path'); + +async function handleCacheClean(cwd) { + return new Promise((resolve, reject) => { + const cachePath = path.join(cwd, '.cache/webpack'); + require('get-folder-size')(cachePath, (err, size) => { + if (err) { + return reject(err); + } + // 大于 5G 清除缓存,修复 webpack 缓存无限增长问题 + // https://github.com/webpack/webpack/issues/13291 + if (size > 5 * 1024 * 1024 * 1024) { + require('fs-extra').removeSync(cachePath); + } + resolve(size); + }); + }); +} + export default (api) => { const { paths, @@ -28,6 +47,7 @@ export default (api) => { async fn({ args = {} }) { const { cleanTmpPathExceptCache, getBundleAndConfigs } = require('../buildDevUtils'); const connectHistoryMiddleware = require('./connectHistoryMiddleware').default; + await handleCacheClean(api.paths.cwd); port = await getPort(process.env.PORT || args.port || api.config.devServer?.port); diff --git a/packages/fes-template/.fes.js b/packages/fes-template/.fes.js index d457db32..072f8593 100644 --- a/packages/fes-template/.fes.js +++ b/packages/fes-template/.fes.js @@ -1,31 +1,32 @@ -import { defineBuildConfig } from '@fesjs/fes' +import { defineBuildConfig } from '@fesjs/fes'; + export default defineBuildConfig({ define: { - __DEV__: false + __DEV__: false, }, html: { - title: '海贼王' + title: '海贼王', }, router: { - mode: 'hash' + mode: 'hash', }, watermark: { - disabled: false + disabled: false, }, access: { roles: { admin: ['*'], - menuTest: ['/', '/menuTest'] - } + menuTest: ['/', '/menuTest'], + }, }, mock: { - prefix: '/v2' + prefix: '/v2', }, proxy: { '/v2': { target: 'https://api.douban.com/', - changeOrigin: true - } + changeOrigin: true, + }, }, layout: { title: 'Fes.js', @@ -37,60 +38,58 @@ export default defineBuildConfig({ { name: 'index', icon: '/wine-outline.svg', - match: ['/route/*'] + match: ['/route/*'], }, { - name: 'store' + name: 'store', }, { name: 'editor', - icon: '/wine-outline.svg' + icon: '/wine-outline.svg', }, { title: '$externalLink', icon: 'UserOutlined', - path: 'https://www.baidu.com' + path: 'https://www.baidu.com', }, { - name: 'mock' + name: 'mock', }, { title: '菜单权限测试', children: [ { title: '子菜单', - path: '/menuTest' + path: '/menuTest', }, - ] + ], }, { - name: 'cssModule' + name: 'cssModule', }, { - name: 'pinia' + name: 'pinia', }, ], menuProps: { - defaultExpandAll: false - } + defaultExpandAll: false, + }, }, devServer: { - port: 8080 + port: 8080, }, enums: { status: [ ['0', '无效的'], - ['1', '有效的'] - ] + ['1', '有效的'], + ], }, vuex: { - strict: true + strict: true, }, dynamicImport: true, monacoEditor: { - languages: ['javascript', 'typescript', 'html', 'json'] + languages: ['javascript', 'typescript', 'html', 'json'], }, - presets: [ - require.resolve('../fes-builder-webpack/lib'), - ] + presets: [require.resolve('../fes-builder-webpack/lib')], }); diff --git a/yarn.lock b/yarn.lock index 1c975758..ee277a07 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6113,6 +6113,11 @@ functions-have-names@^1.2.2: resolved "https://registry.npmmirror.com/functions-have-names/-/functions-have-names-1.2.3.tgz#0404fe4ee2ba2f607f0e0ec3c80bae994133b834" integrity sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ== +gar@^1.0.4: + version "1.0.4" + resolved "https://registry.npmmirror.com/gar/-/gar-1.0.4.tgz#f777bc7db425c0572fdeb52676172ca1ae9888b8" + integrity sha512-w4n9cPWyP7aHxKxYHFQMegj7WIAsL/YX/C4Bs5Rr8s1H9M1rNtRWRsw+ovYMkXDQ5S4ZbYHsHAPmevPjPgw44w== + gensync@^1.0.0-beta.2: version "1.0.0-beta.2" resolved "https://registry.npmmirror.com/gensync/-/gensync-1.0.0-beta.2.tgz#32a6ee76c3d7f52d46b2b1ae5d93fea8580a25e0" @@ -6123,6 +6128,14 @@ get-caller-file@^2.0.1, get-caller-file@^2.0.5: resolved "https://registry.npmmirror.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e" integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg== +get-folder-size@^2.0.1: + version "2.0.1" + resolved "https://registry.npmmirror.com/get-folder-size/-/get-folder-size-2.0.1.tgz#3fe0524dd3bad05257ef1311331417bcd020a497" + integrity sha512-+CEb+GDCM7tkOS2wdMKTn9vU7DgnKUTuDlehkNJKNSovdCOVxs14OfKCk4cvSaR3za4gj+OBdl9opPN9xrJ0zA== + dependencies: + gar "^1.0.4" + tiny-each-async "2.0.3" + get-intrinsic@^1.0.2, get-intrinsic@^1.1.0, get-intrinsic@^1.1.1, get-intrinsic@^1.1.3: version "1.1.3" resolved "https://registry.npmmirror.com/get-intrinsic/-/get-intrinsic-1.1.3.tgz#063c84329ad93e83893c7f4f243ef63ffa351385" @@ -10662,6 +10675,11 @@ thunky@^1.0.2: resolved "https://registry.npmmirror.com/thunky/-/thunky-1.1.0.tgz#5abaf714a9405db0504732bbccd2cedd9ef9537d" integrity sha512-eHY7nBftgThBqOyHGVN+l8gF0BucP09fMo0oO/Lb0w1OF80dJv+lDVpXG60WMQvkcxAkNybKsrEIE3ZtKGmPrA== +tiny-each-async@2.0.3: + version "2.0.3" + resolved "https://registry.npmmirror.com/tiny-each-async/-/tiny-each-async-2.0.3.tgz#8ebbbfd6d6295f1370003fbb37162afe5a0a51d1" + integrity sha512-5ROII7nElnAirvFn8g7H7MtpfV1daMcyfTGQwsn/x2VtyV+VPiO5CjReCJtWLvoKTDEDmZocf3cNPraiMnBXLA== + tmp@^0.0.33: version "0.0.33" resolved "https://registry.npmmirror.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9"