From 55f0b7b6fc0c41507dd75dfd39043a5c82c0d84d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E4=B8=80=E4=BA=8C?= Date: Sat, 7 Aug 2021 18:23:41 +0800 Subject: [PATCH] refactor: use afterPack.js to prepare worker dependencies --- forge.config.js | 2 +- scripts/afterPack.js | 10 ++++++++++ webpack.plugins.js | 8 -------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/forge.config.js b/forge.config.js index 3ea08485..10362556 100644 --- a/forge.config.js +++ b/forge.config.js @@ -21,7 +21,7 @@ const config = { asar: { unpack: '**/.webpack/main/*.worker.*', }, - extraResource: ['.webpack/node_modules', 'localization', 'template/wiki', 'build-resources/menubar@2x.png', 'build-resources/menubarTemplate@2x.png'], + extraResource: ['localization', 'template/wiki', 'build-resources/menubar@2x.png', 'build-resources/menubarTemplate@2x.png'], mac: { category: 'productivity', target: 'dmg', diff --git a/scripts/afterPack.js b/scripts/afterPack.js index 7bc27e03..1fff58a8 100644 --- a/scripts/afterPack.js +++ b/scripts/afterPack.js @@ -22,10 +22,20 @@ const keepingLprojRegEx = /(en|zh_CN)\.lproj/g; */ exports.default = async (buildPath, electronVersion, platform, arch, callback) => { const cwd = path.join(buildPath, '..'); + const projectRoot = path.join(__dirname, '..'); + + /** delete useless lproj files to make it clean */ const lproj = glob.sync('*.lproj', { cwd }); const pathsToRemove = lproj.filter((dir) => !keepingLprojRegEx.test(dir)).map((dir) => path.join(cwd, dir)); if (platform === 'darwin') { await Promise.all(pathsToRemove.map((dir) => fs.remove(dir))); } + /** copy npm packages with node-worker dependencies with binary or __filename usages, which can't be prepare properly by webpack */ + if (['production', 'test'].includes(process.env.NODE_ENV)) { + console.log('Copying tiddlywiki dependency to dist'); + await fs.copy(path.join(projectRoot, 'node_modules/@tiddlygit/tiddlywiki'), path.join(cwd, 'node_modules/@tiddlygit/tiddlywiki')); + await fs.copy(path.join(projectRoot, 'node_modules/dugite'), path.join(cwd, 'node_modules/dugite')); + } + /** complete this hook */ callback(); }; diff --git a/webpack.plugins.js b/webpack.plugins.js index a852da51..96e4c6d4 100644 --- a/webpack.plugins.js +++ b/webpack.plugins.js @@ -26,14 +26,6 @@ exports.main = _.compact([ // to is relative to ./.webpack/main/ patterns: [{ from: 'localization', to: 'localization' }], }), - ['production', 'test'].includes(process.env.NODE_ENV) && - new EventHooksPlugin({ - afterEmit: async (compilation, done) => { - console.log('Copying tiddlywiki dependency to dist'); - await fs.copy('node_modules/@tiddlygit/tiddlywiki', './.webpack/node_modules/@tiddlygit/tiddlywiki'); - await fs.copy('node_modules/dugite', './.webpack/node_modules/dugite'); - }, - }), new CircularDependencyPlugin({ // exclude detection of files based on a RegExp exclude: /node_modules/,