refactor: use afterPack.js to prepare worker dependencies

This commit is contained in:
林一二 2021-08-07 18:23:41 +08:00
parent 34af575f39
commit 55f0b7b6fc
3 changed files with 11 additions and 9 deletions

View file

@ -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',

View file

@ -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();
};

View file

@ -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/,