From 567ca55fbe278662525a51ecdac9ad06e6e096b8 Mon Sep 17 00:00:00 2001 From: lizhouze Date: Mon, 21 Mar 2022 22:06:57 +0800 Subject: [PATCH] fixed 034d03b from https://gitee.com/kage1/developtools_ace-js2bundle/pulls/210 lizhouze@huawei.com Signed-off-by: lizhouze --- ace-loader/src/compile-plugin.js | 23 ++++++++++++++++++++++- ace-loader/src/module-script.js | 2 +- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/ace-loader/src/compile-plugin.js b/ace-loader/src/compile-plugin.js index 0d86363..6940dfb 100644 --- a/ace-loader/src/compile-plugin.js +++ b/ace-loader/src/compile-plugin.js @@ -20,7 +20,11 @@ import JavascriptModulesPlugin from 'webpack/lib/javascript/JavascriptModulesPlu import CachedSource from 'webpack-sources/lib/CachedSource'; import ConcatSource from 'webpack-sources/lib/ConcatSource'; -import { circularFile } from './util'; +import { + circularFile, + useOSFiles, + mkDir +} from './util'; let mStats; let mErrorCount = 0; @@ -85,6 +89,10 @@ class ResultStates { }); compiler.hooks.done.tap('Result States', (stats) => { + if (process.env.isPreview && process.env.aceSoPath && + useOSFiles && useOSFiles.size > 0) { + writeUseOSFiles(); + } mStats = stats; warningCount = 0; noteCount = 0; @@ -241,4 +249,17 @@ function printError(buildPath) { } } +function writeUseOSFiles() { + let oldInfo = ''; + if (!fs.existsSync(process.env.aceSoPath)) { + const parent = path.join(process.env.aceSoPath, '..'); + if (!(fs.existsSync(parent) && !fs.statSync(parent).isFile())) { + mkDir(parent); + } + } else { + oldInfo = fs.readFileSync(process.env.aceSoPath, 'utf-8') + '\n'; + } + fs.writeFileSync(process.env.aceSoPath, oldInfo + Array.from(useOSFiles).join('\n')); +} + module.exports = ResultStates; diff --git a/ace-loader/src/module-script.js b/ace-loader/src/module-script.js index 3672138..75f0f04 100644 --- a/ace-loader/src/module-script.js +++ b/ace-loader/src/module-script.js @@ -18,7 +18,7 @@ import { } from './util'; module.exports = function(source, map) { - source = parseRequireModule(source); + source = parseRequireModule(source, this.resourcePath); this.cacheable && this.cacheable() const callback = this.async() callback(null, source, map) -- Gitee