Commit 359a08e0c7ae884a43f11b9ce5e9fe0b4d034877

Authored by 刘汉宸
1 parent 8616363c
Exists in master

chore: 异步编译,加快打包速度

Showing 1 changed file with 13 additions and 21 deletions   Show diff stats
webpack/release.js
1 1 const fs = require('fs');
2 2 const path = require('path');
3   -const { execSync } = require('child_process');
  3 +const { exec } = require('child_process');
4 4  
5 5 const inputPath = path.resolve(__dirname, '../packages');
6 6 const outputPath = path.resolve(__dirname, '../release');
... ... @@ -36,35 +36,27 @@ if (fs.existsSync(outputPath)) {
36 36 delPath(outputPath);
37 37 }
38 38  
39   -// 步编译
  39 +// 步编译
40 40 fs.readdirSync(inputPath).forEach(name => {
41 41 const filePath = path.resolve(inputPath, name);
42 42 if (fs.lstatSync(filePath).isDirectory()) {
43 43 if (fs.existsSync(path.resolve(filePath, 'index.vue'))) {
44 44 console.log(`Build ${name}...`);
45   - execSync(`vue-cli-service build --target lib --name zui-${name} --dest release/${name} packages/${name}/index.vue`, function (error, stdout, stderr) {
  45 + exec(`vue-cli-service build --target lib --name zui-${name} --dest release/${name} packages/${name}/index.vue`, function (error, stdout, stderr) {
46 46 if (error) {
47 47 throw error;
48 48 }
  49 + const destPath = path.resolve(outputPath, name);
  50 + fs.readdirSync(destPath).forEach(file => {
  51 + if (file !== `zui-${name}.css`) {
  52 + if (file === `zui-${name}.umd.min.js`) {
  53 + fs.renameSync(path.resolve(destPath, file), path.resolve(destPath, `zui-${name}.js`));
  54 + } else {
  55 + fs.unlinkSync(path.resolve(destPath, file));
  56 + }
  57 + }
  58 + });
49 59 });
50 60 }
51 61 }
52 62 });
53   -
54   -// 编译完成后删除无用的文件
55   -fs.readdirSync(outputPath).forEach(name => {
56   - const filePath = path.resolve(outputPath, name);
57   - if (fs.lstatSync(filePath).isDirectory()) {
58   - fs.readdirSync(filePath).forEach(file => {
59   - if (file !== `zui-${name}.css`) {
60   - if (file === `zui-${name}.umd.min.js`) {
61   - fs.renameSync(path.resolve(filePath, file), path.resolve(filePath, `zui-${name}.js`));
62   - } else {
63   - fs.unlinkSync(path.resolve(filePath, file));
64   - }
65   - }
66   - });
67   - } else {
68   - fs.unlinkSync(path.resolve(outputPath, name));
69   - }
70   -});
... ...