From 359a08e0c7ae884a43f11b9ce5e9fe0b4d034877 Mon Sep 17 00:00:00 2001 From: 刘汉宸 Date: Tue, 30 Jun 2020 10:26:56 +0800 Subject: [PATCH] chore: 异步编译,加快打包速度 --- webpack/release.js | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/webpack/release.js b/webpack/release.js index 7d62437..b701c00 100644 --- a/webpack/release.js +++ b/webpack/release.js @@ -1,6 +1,6 @@ const fs = require('fs'); const path = require('path'); -const { execSync } = require('child_process'); +const { exec } = require('child_process'); const inputPath = path.resolve(__dirname, '../packages'); const outputPath = path.resolve(__dirname, '../release'); @@ -36,35 +36,27 @@ if (fs.existsSync(outputPath)) { delPath(outputPath); } -// 同步编译 +// 异步编译 fs.readdirSync(inputPath).forEach(name => { const filePath = path.resolve(inputPath, name); if (fs.lstatSync(filePath).isDirectory()) { if (fs.existsSync(path.resolve(filePath, 'index.vue'))) { console.log(`Build ${name}...`); - execSync(`vue-cli-service build --target lib --name zui-${name} --dest release/${name} packages/${name}/index.vue`, function (error, stdout, stderr) { + exec(`vue-cli-service build --target lib --name zui-${name} --dest release/${name} packages/${name}/index.vue`, function (error, stdout, stderr) { if (error) { throw error; } + const destPath = path.resolve(outputPath, name); + fs.readdirSync(destPath).forEach(file => { + if (file !== `zui-${name}.css`) { + if (file === `zui-${name}.umd.min.js`) { + fs.renameSync(path.resolve(destPath, file), path.resolve(destPath, `zui-${name}.js`)); + } else { + fs.unlinkSync(path.resolve(destPath, file)); + } + } + }); }); } } }); - -// 编译完成后删除无用的文件 -fs.readdirSync(outputPath).forEach(name => { - const filePath = path.resolve(outputPath, name); - if (fs.lstatSync(filePath).isDirectory()) { - fs.readdirSync(filePath).forEach(file => { - if (file !== `zui-${name}.css`) { - if (file === `zui-${name}.umd.min.js`) { - fs.renameSync(path.resolve(filePath, file), path.resolve(filePath, `zui-${name}.js`)); - } else { - fs.unlinkSync(path.resolve(filePath, file)); - } - } - }); - } else { - fs.unlinkSync(path.resolve(outputPath, name)); - } -}); -- libgit2 0.21.0