diff --git a/compiler/src/gen_abc_plugin.ts b/compiler/src/gen_abc_plugin.ts index a8c4a3a..30dc6c0 100644 --- a/compiler/src/gen_abc_plugin.ts +++ b/compiler/src/gen_abc_plugin.ts @@ -142,6 +142,11 @@ export class GenAbcPlugin { return; } + if (projectConfig.compileMode === ESMODULE) { + removeDir(output); + removeDir(projectConfig.nodeModulesPath); + } + compiler.hooks.compilation.tap('GenAbcPlugin', (compilation) => { if (projectConfig.compileMode === JSBUNDLE || projectConfig.compileMode === undefined) { return; @@ -167,7 +172,6 @@ export class GenAbcPlugin { if (projectConfig.compileMode === ESMODULE) { return; } - removeDir(output); Object.keys(compilation.assets).forEach(key => { // choose *.js if (output && path.extname(key) === EXTNAME_JS) { @@ -372,6 +376,8 @@ function writeFileSync(inputString: string, output: string, jsBundleFile: string fs.writeFileSync(cacheOutputPath, inputString); if (fs.existsSync(cacheOutputPath)) { const fileSize: any = fs.statSync(cacheOutputPath).size; + output = toUnixPath(output); + cacheOutputPath = toUnixPath(cacheOutputPath); intermediateJsBundle.push({path: output, size: fileSize, cacheOutputPath: cacheOutputPath}); } else { logger.error(red, `ETS:ERROR Failed to convert file ${jsBundleFile} to bin. ${output} is lost`, reset); @@ -425,8 +431,6 @@ function splitJsBundlesBySize(bundleArray: Array, groupNumber: number): an } function invokeWorkersModuleToGenAbc(moduleInfos: Array): void { - removeDir(buildPathInfo); - removeDir(projectConfig.nodeModulesPath); invokeCluterModuleToAbc(); } @@ -841,7 +845,7 @@ function writeHashJson(): void { mkdirsSync(path.dirname(abcFile)); fs.copyFileSync(cacheAbcFilePath, abcFile); } - if (fs.existsSync(intermediateJsBundle[i].path)) { + if (process.env.cachePath === undefined && fs.existsSync(intermediateJsBundle[i].path)) { fs.unlinkSync(intermediateJsBundle[i].path); } } diff --git a/compiler/src/gen_module_abc.ts b/compiler/src/gen_module_abc.ts index 3490442..1426cee 100644 --- a/compiler/src/gen_module_abc.ts +++ b/compiler/src/gen_module_abc.ts @@ -60,7 +60,7 @@ function es2abcByWorkers(jsonInput: string, cmd: string): Promise { for (let i = 0; i < inputPaths.length; ++i) { const input: string = inputPaths[i].tempFilePath; const abcFile: string = input.replace(/\.js$/, '.abc'); - const singleCmd: any = `${cmd} "${input}" --output "${abcFile}"`; + const singleCmd: any = `${cmd} "${input}" --output "${abcFile}" --source-file "${input}"`; logger.debug('gen abc cmd is: ', singleCmd); try { childProcess.execSync(singleCmd); diff --git a/compiler/webpack.config.js b/compiler/webpack.config.js index 69a06e7..a9c2391 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,28 @@ function setGenAbcPlugin(env, config) { } } +function setCleanWebpackPlugin(workerFile, config) { + if (projectConfig.compileMode === 'esmodule') { + return; + } + 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 +377,7 @@ module.exports = (env, argv) => { const workerFile = readWorkerFile(); setOptimizationConfig(config, workerFile); setCopyPluginConfig(config); + setCleanWebpackPlugin(workerFile, config); if (env.isPreview !== "true") { loadWorker(projectConfig, workerFile);