fix: webpack 缓存不断叠加 (#167)

This commit is contained in:
qlin 2023-01-06 17:44:30 +08:00 committed by GitHub
parent eee453b601
commit ab4cc6a5a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 136 additions and 97 deletions

View File

@ -1,69 +1,71 @@
{ {
"name": "@fesjs/builder-webpack", "name": "@fesjs/builder-webpack",
"version": "3.0.0-rc.2", "version": "3.0.0-rc.2",
"description": "@fesjs/builder-webpack", "description": "@fesjs/builder-webpack",
"main": "lib/index.js", "main": "lib/index.js",
"types": "types.d.ts", "types": "types.d.ts",
"files": [ "files": [
"lib", "lib",
"types.d.ts" "types.d.ts"
], ],
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/WeBankFinTech/fes.js.git", "url": "git+https://github.com/WeBankFinTech/fes.js.git",
"directory": "packages/fes-builder-webpack" "directory": "packages/fes-builder-webpack"
}, },
"keywords": [ "keywords": [
"fes" "fes"
], ],
"author": "qlin", "author": "qlin",
"license": "MIT", "license": "MIT",
"bugs": { "bugs": {
"url": "https://github.com/WeBankFinTech/fes.js/issues" "url": "https://github.com/WeBankFinTech/fes.js/issues"
}, },
"homepage": "https://github.com/WeBankFinTech/fes.js#readme", "homepage": "https://github.com/WeBankFinTech/fes.js#readme",
"publishConfig": { "publishConfig": {
"access": "public" "access": "public"
}, },
"dependencies": { "dependencies": {
"@babel/core": "^7.16.0", "@babel/core": "^7.16.0",
"@babel/plugin-proposal-do-expressions": "^7.16.0", "@babel/plugin-proposal-do-expressions": "^7.16.0",
"@babel/plugin-proposal-export-default-from": "^7.16.0", "@babel/plugin-proposal-export-default-from": "^7.16.0",
"@babel/plugin-proposal-function-bind": "^7.16.0", "@babel/plugin-proposal-function-bind": "^7.16.0",
"@babel/plugin-proposal-pipeline-operator": "^7.16.0", "@babel/plugin-proposal-pipeline-operator": "^7.16.0",
"@babel/plugin-transform-runtime": "^7.16.4", "@babel/plugin-transform-runtime": "^7.16.4",
"@babel/preset-env": "^7.16.4", "@babel/preset-env": "^7.16.4",
"@babel/preset-typescript": "^7.15.0", "@babel/preset-typescript": "^7.15.0",
"@fesjs/utils": "3.0.0-rc.2", "@fesjs/utils": "3.0.0-rc.2",
"@vue/babel-plugin-jsx": "^1.1.1", "@vue/babel-plugin-jsx": "^1.1.1",
"autoprefixer": "^10.2.4", "autoprefixer": "^10.2.4",
"babel-loader": "^8.2.2", "babel-loader": "^8.2.2",
"babel-plugin-import": "1.13.3", "babel-plugin-import": "1.13.3",
"cli-highlight": "^2.1.4", "cli-highlight": "^2.1.4",
"cliui": "7.0.4", "cliui": "7.0.4",
"connect-history-api-fallback": "^1.6.0", "connect-history-api-fallback": "^1.6.0",
"copy-webpack-plugin": "^7.0.0", "copy-webpack-plugin": "^7.0.0",
"css-loader": "^5.0.1", "css-loader": "^5.0.1",
"css-minimizer-webpack-plugin": "^3.0.0", "css-minimizer-webpack-plugin": "^3.0.0",
"html-webpack-plugin": "^5.0.0", "fs-extra": "^10.0.0",
"html-webpack-tags-plugin": "^3.0.0", "html-webpack-plugin": "^5.0.0",
"less": "3.9.0", "html-webpack-tags-plugin": "^3.0.0",
"less-loader": "^8.0.0", "get-folder-size": "^2.0.1",
"mini-css-extract-plugin": "^1.3.5", "less": "3.9.0",
"postcss": "8.3.0", "less-loader": "^8.0.0",
"postcss-flexbugs-fixes": "^5.0.2", "mini-css-extract-plugin": "^1.3.5",
"postcss-loader": "^4.2.0", "postcss": "8.3.0",
"postcss-safe-parser": "^6.0.0", "postcss-flexbugs-fixes": "^5.0.2",
"style-loader": "^2.0.0", "postcss-loader": "^4.2.0",
"vue-loader": "^16.1.2", "postcss-safe-parser": "^6.0.0",
"webpack": "^5.69.0", "style-loader": "^2.0.0",
"webpack-bundle-analyzer": "^4.4.0", "vue-loader": "^16.1.2",
"webpack-chain": "^6.5.1", "webpack": "^5.69.0",
"webpack-dev-server": "^4.8.1", "webpack-bundle-analyzer": "^4.4.0",
"webpackbar": "^5.0.2" "webpack-chain": "^6.5.1",
}, "webpack-dev-server": "^4.8.1",
"peerDependencies": { "webpackbar": "^5.0.2"
"@fesjs/fes": "3.0.0-rc.2", },
"core-js": "^3.27.0" "peerDependencies": {
} "@fesjs/fes": "3.0.0-rc.2",
} "core-js": "^3.27.0"
}
}

View File

@ -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) => { export default (api) => {
const { const {
paths, paths,
@ -28,6 +47,7 @@ export default (api) => {
async fn({ args = {} }) { async fn({ args = {} }) {
const { cleanTmpPathExceptCache, getBundleAndConfigs } = require('../buildDevUtils'); const { cleanTmpPathExceptCache, getBundleAndConfigs } = require('../buildDevUtils');
const connectHistoryMiddleware = require('./connectHistoryMiddleware').default; const connectHistoryMiddleware = require('./connectHistoryMiddleware').default;
await handleCacheClean(api.paths.cwd);
port = await getPort(process.env.PORT || args.port || api.config.devServer?.port); port = await getPort(process.env.PORT || args.port || api.config.devServer?.port);

View File

@ -1,31 +1,32 @@
import { defineBuildConfig } from '@fesjs/fes' import { defineBuildConfig } from '@fesjs/fes';
export default defineBuildConfig({ export default defineBuildConfig({
define: { define: {
__DEV__: false __DEV__: false,
}, },
html: { html: {
title: '海贼王' title: '海贼王',
}, },
router: { router: {
mode: 'hash' mode: 'hash',
}, },
watermark: { watermark: {
disabled: false disabled: false,
}, },
access: { access: {
roles: { roles: {
admin: ['*'], admin: ['*'],
menuTest: ['/', '/menuTest'] menuTest: ['/', '/menuTest'],
} },
}, },
mock: { mock: {
prefix: '/v2' prefix: '/v2',
}, },
proxy: { proxy: {
'/v2': { '/v2': {
target: 'https://api.douban.com/', target: 'https://api.douban.com/',
changeOrigin: true changeOrigin: true,
} },
}, },
layout: { layout: {
title: 'Fes.js', title: 'Fes.js',
@ -37,60 +38,58 @@ export default defineBuildConfig({
{ {
name: 'index', name: 'index',
icon: '/wine-outline.svg', icon: '/wine-outline.svg',
match: ['/route/*'] match: ['/route/*'],
}, },
{ {
name: 'store' name: 'store',
}, },
{ {
name: 'editor', name: 'editor',
icon: '/wine-outline.svg' icon: '/wine-outline.svg',
}, },
{ {
title: '$externalLink', title: '$externalLink',
icon: 'UserOutlined', icon: 'UserOutlined',
path: 'https://www.baidu.com' path: 'https://www.baidu.com',
}, },
{ {
name: 'mock' name: 'mock',
}, },
{ {
title: '菜单权限测试', title: '菜单权限测试',
children: [ children: [
{ {
title: '子菜单', title: '子菜单',
path: '/menuTest' path: '/menuTest',
}, },
] ],
}, },
{ {
name: 'cssModule' name: 'cssModule',
}, },
{ {
name: 'pinia' name: 'pinia',
}, },
], ],
menuProps: { menuProps: {
defaultExpandAll: false defaultExpandAll: false,
} },
}, },
devServer: { devServer: {
port: 8080 port: 8080,
}, },
enums: { enums: {
status: [ status: [
['0', '无效的'], ['0', '无效的'],
['1', '有效的'] ['1', '有效的'],
] ],
}, },
vuex: { vuex: {
strict: true strict: true,
}, },
dynamicImport: true, dynamicImport: true,
monacoEditor: { monacoEditor: {
languages: ['javascript', 'typescript', 'html', 'json'] languages: ['javascript', 'typescript', 'html', 'json'],
}, },
presets: [ presets: [require.resolve('../fes-builder-webpack/lib')],
require.resolve('../fes-builder-webpack/lib'),
]
}); });

View File

@ -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" resolved "https://registry.npmmirror.com/functions-have-names/-/functions-have-names-1.2.3.tgz#0404fe4ee2ba2f607f0e0ec3c80bae994133b834"
integrity sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ== 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: gensync@^1.0.0-beta.2:
version "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" 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" resolved "https://registry.npmmirror.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e"
integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg== 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: get-intrinsic@^1.0.2, get-intrinsic@^1.1.0, get-intrinsic@^1.1.1, get-intrinsic@^1.1.3:
version "1.1.3" version "1.1.3"
resolved "https://registry.npmmirror.com/get-intrinsic/-/get-intrinsic-1.1.3.tgz#063c84329ad93e83893c7f4f243ef63ffa351385" 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" resolved "https://registry.npmmirror.com/thunky/-/thunky-1.1.0.tgz#5abaf714a9405db0504732bbccd2cedd9ef9537d"
integrity sha512-eHY7nBftgThBqOyHGVN+l8gF0BucP09fMo0oO/Lb0w1OF80dJv+lDVpXG60WMQvkcxAkNybKsrEIE3ZtKGmPrA== 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: tmp@^0.0.33:
version "0.0.33" version "0.0.33"
resolved "https://registry.npmmirror.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9" resolved "https://registry.npmmirror.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9"