Add clean webpack plugin

Signed-off-by: zhangrengao <zhangrengao1@huawei.com>
Change-Id: I53c9e91211ad113c8322b7165139522a278fb0f6
This commit is contained in:
zhangrengao
2022-08-26 22:07:23 +08:00
parent 91bf2e7182
commit 22de16e58e
2 changed files with 21 additions and 1 deletions
-1
View File
@@ -142,7 +142,6 @@ export class GenAbcPlugin {
return;
}
removeDir(output);
if (projectConfig.compileMode === ESMODULE) {
removeDir(projectConfig.nodeModulesPath);
}
+21
View File
@@ -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);