diff --git a/compiler/src/gen_abc_plugin.ts b/compiler/src/gen_abc_plugin.ts index fe1be97..5b11e15 100644 --- a/compiler/src/gen_abc_plugin.ts +++ b/compiler/src/gen_abc_plugin.ts @@ -142,7 +142,6 @@ export class GenAbcPlugin { return; } - removeDir(output); if (projectConfig.compileMode === ESMODULE) { removeDir(projectConfig.nodeModulesPath); } diff --git a/compiler/webpack.config.js b/compiler/webpack.config.js index 69a06e7..ebb7678 100644 --- a/compiler/webpack.config.js +++ b/compiler/webpack.config.js @@ -17,6 +17,7 @@ const path = require('path'); const fs = require('fs'); const CopyPlugin = require('copy-webpack-plugin'); const Webpack = require('webpack'); +const { CleanWebpackPlugin } = require('clean-webpack-plugin'); const { GenAbcPlugin } = require('./lib/gen_abc_plugin'); const { OHMResolverPlugin } = require('./lib/resolve_ohm_url'); const buildPipeServer = require('./server/build_pipe_server'); @@ -344,6 +345,25 @@ function setGenAbcPlugin(env, config) { } } +function setCleanWebpackPlugin(workerFile, config) { + let cleanPath = []; + cleanPath.push(projectConfig.buildPath); + if (workerFile) { + let workerFilesPath = Object.keys(workerFile); + for (let workerFilePath of workerFilesPath) { + cleanPath.push(path.join(projectConfig.buildPath, workerFilePath, '..')); + } + } + + config.plugins.push( + new CleanWebpackPlugin({ + dry: false, + dangerouslyAllowCleanPatternsOutsideProject: true, + cleanOnceBeforeBuildPatterns: cleanPath + }) + ); +} + module.exports = (env, argv) => { const config = {}; setProjectConfig(env); @@ -354,6 +374,7 @@ module.exports = (env, argv) => { const workerFile = readWorkerFile(); setOptimizationConfig(config, workerFile); setCopyPluginConfig(config); + setCleanWebpackPlugin(workerFile, config); if (env.isPreview !== "true") { loadWorker(projectConfig, workerFile);