diff --git a/ace-loader/src/compile-plugin.js b/ace-loader/src/compile-plugin.js index 1ca73f0a742574c652fb4c60df79e17715702f76..2ad8ed41f07e02fe830e2841f80b22fbe230f441 100644 --- a/ace-loader/src/compile-plugin.js +++ b/ace-loader/src/compile-plugin.js @@ -49,7 +49,8 @@ class ResultStates { apply(compiler) { const buildPath = this.options.build; - const modulePaths = new Set(); + const commonPaths = new Set(); + const i18nPaths = new Set(); compiler.hooks.compilation.tap('toFindModule', (compilation) => { compilation.hooks.buildModule.tap("findModule", (module) => { @@ -58,18 +59,26 @@ class ResultStates { const afterNodeModules = module.context.replace(beforNodeModules, '').replace('node_modules' + path.sep, ''); const src = afterNodeModules.substr(0, afterNodeModules.indexOf(path.sep)); - const modulePath = - path.resolve(beforNodeModules, 'node_modules', src, 'src', 'js', 'share'); - if (fs.existsSync(modulePath)) { - modulePaths.add(modulePath) + const commonPath = + path.resolve(beforNodeModules, 'node_modules', src, 'src', 'js', 'common'); + if (fs.existsSync(commonPath)) { + commonPaths.add(commonPath) + } + const i18nPath = + path.resolve(beforNodeModules, 'node_modules', src, 'src', 'js', 'i18n'); + if (fs.existsSync(i18nPath)) { + i18nPaths.add(i18nPath) } } }); }); compiler.hooks.afterCompile.tap('copyFindModule', () => { - for (let modulePath of modulePaths) { - circularFile(modulePath, path.resolve(buildPath, '../share')); + for (let commonPath of commonPaths) { + circularFile(commonPath, path.resolve(buildPath, '../share/common')); + } + for (let i18nPath of i18nPaths) { + circularFile(i18nPath, path.resolve(buildPath, '../share/i18n')); } }); diff --git a/ace-loader/src/resource-plugin.js b/ace-loader/src/resource-plugin.js index de513ec7d56ec4cc6e3ef2639a7b264d70881805..58068449e71002008125566fde946185599f24a3 100644 --- a/ace-loader/src/resource-plugin.js +++ b/ace-loader/src/resource-plugin.js @@ -67,8 +67,7 @@ function copyFile(input, output) { function circularFile(inputPath, outputPath, ext) { const realPath = path.join(inputPath, ext); - const localI18n = path.join(input, 'i18n'); - if (!fs.existsSync(realPath) || realPath === output || realPath === localI18n) { + if (!fs.existsSync(realPath) || realPath === output) { return; } fs.readdirSync(realPath).forEach(function(file_) { @@ -77,18 +76,20 @@ function circularFile(inputPath, outputPath, ext) { if (fileStat.isFile()) { const baseName = path.basename(file); const extName = path.extname(file); + const outputFile = path.join(outputPath, ext, path.basename(file_)); + if (outputFile === path.join(output, 'manifest.json')) { + return; + } if (FILE_EXT_NAME.indexOf(extName) < 0 && baseName !== '.DS_Store') { - const outputFile = path.join(outputPath, ext, path.basename(file_)); - if (outputFile === path.join(output, 'manifest.json')) { - return; - } - if (fs.existsSync(outputFile)) { - const outputFileStat = fs.statSync(outputFile); - if (outputFileStat.isFile() && fileStat.size !== outputFileStat.size) { - copyFile(file, outputFile); - } - } else { - copyFile(file, outputFile); + toCopyFile(file, outputFile, fileStat) + } else if (extName === '.json') { + const parent = path.join(file, '..'); + const parent_ = path.join(parent, '..'); + if (path.parse(parent).name === 'i18n' && path.parse(parent_).name === 'share') { + toCopyFile(file, outputFile, fileStat) + } else if (path.parse(parent).name === 'styles' && + path.parse(parent_).name === 'resources') { + toCopyFile(file, outputFile, fileStat) } } } else if (fileStat.isDirectory()) { @@ -97,6 +98,17 @@ function circularFile(inputPath, outputPath, ext) { }); } +function toCopyFile(file, outputFile, fileStat) { + if (fs.existsSync(outputFile)) { + const outputFileStat = fs.statSync(outputFile); + if (outputFileStat.isFile() && fileStat.size !== outputFileStat.size) { + copyFile(file, outputFile); + } + } else { + copyFile(file, outputFile); + } +} + class ResourcePlugin { constructor(input_, output_, manifestFilePath_, watchCSSFiles_) { input = input_;