公司有个三年前的项目用的是 webpack 5.22.0 的版本,一天开发下来发现缓存文件 20 个 G 左右,就是这个文件node_modules\.cache\webpack
。
有升级到 5.75.0 版本还是会这样,为什么?
求大佬们给个解决方案。。。
rules 配置
oneOf: [ { test: /\.(js|jsx|ts|tsx)$/, exclude: /node-modules/, loader: 'babel-loader', options: { // 开启 babel 缓存 cacheDirectory: true } }, { test: /\.(png|svg|jpg|jpeg|gif)$/, use: [ { loader: 'url-loader', options: { limit: 8192, name: 'imgs/[name]_[hash:8][ext]', fallback: 'file-loader?name=imgs/[name]_[hash:8][ext]' } } ] } ]
babel 配置
{ "presets": [ "@babel/preset-env", "@babel/preset-react", "@babel/preset-typescript" ], "plugins": [ "@babel/plugin-syntax-dynamic-import", "@babel/plugin-transform-runtime", [ "@babel/plugin-proposal-decorators", { "legacy": true } ], [ "import", { "libraryName": "antd", "libraryDirectory": "lib", "style": true } ], [ "@babel/plugin-proposal-class-properties", { "loose": true } ] ] }