Sfoglia il codice sorgente

chore: 修改编译前清空文件夹

xyh 2 anni fa
parent
commit
a9f6d5eaa3

+ 0 - 1
packages/webpack/config/webpack.config.js

@@ -37,7 +37,6 @@ const config = {
     filename: fileName,
     chunkFilename: fileName,
     assetModuleFilename: 'static/assets/[name].[hash][ext]',
-    clean: true,
     publicPath: assetsPublicPath,
   },
   module: {

+ 1 - 0
packages/webpack/package.json

@@ -29,6 +29,7 @@
     "eslint-webpack-plugin": "^3.2.0",
     "file-loader": "^6.2.0",
     "fork-ts-checker-webpack-plugin": "7.3.0",
+    "fs-extra": "^11.1.1",
     "html-webpack-plugin": "^5.5.0",
     "identity-obj-proxy": "^3.0.0",
     "jest-environment-jsdom": "^29.3.1",

+ 6 - 2
packages/webpack/scripts/build.js

@@ -1,8 +1,9 @@
 const webpack = require('webpack');
 const chalk = require('chalk');
 const config = require('../config/webpack.config');
-const {clearConsole} = require('./utils');
-const {errorLogger} = require('./utils');
+const {clearConsole, errorLogger} = require('./utils');
+const {outputPath} = require('../config/paths');
+const fs = require('fs-extra');
 
 const MAX_CHUNK_SIZE = Number(process.env.MAX_CHUNK_SIZE ?? 0);
 
@@ -79,6 +80,9 @@ function printAssets(assets) {
 }
 try {
   const compiler = webpack(config);
+
+  fs.emptyDirSync(outputPath);
+
   compiler.run(function (err, stats) {
     if (err) {
       errorLogger('Failed to compile');

+ 3 - 0
pnpm-lock.yaml

@@ -297,6 +297,9 @@ importers:
       fork-ts-checker-webpack-plugin:
         specifier: 7.3.0
         version: 7.3.0(typescript@4.9.4)(webpack@5.75.0)
+      fs-extra:
+        specifier: ^11.1.1
+        version: 11.1.1
       html-webpack-plugin:
         specifier: ^5.5.0
         version: 5.5.0(webpack@5.75.0)