Skip to content
This repository was archived by the owner on Jul 16, 2022. It is now read-only.

Commit 562d612

Browse files
committed
feat(vue): Add nsc vue build to compile multiple project with vue-cli/webpack
1 parent 4e89acf commit 562d612

File tree

6 files changed

+168
-35
lines changed

6 files changed

+168
-35
lines changed

packages/cli-plugin-vue/index.js

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,55 @@
1-
/* eslint-disable no-unused-vars */
2-
module.exports = (api, config) => {};
1+
/* eslint-disable no-unused-vars,no-case-declarations */
2+
const path = require('path');
3+
const { info, chalk, warn } = require('@vue/cli-shared-utils');
4+
const fs = require('fs');
5+
const multipleBuild = require('./src/command/multiple-build');
6+
7+
module.exports = (api, config) => {
8+
api.registerCommand(
9+
'vue',
10+
{
11+
usage: '<build|check> <pattern> [options]',
12+
description: 'Build multiple vue app',
13+
options: {
14+
'-e, --execute <cmd>': {
15+
type: String,
16+
description: 'Run command to build a vue application'
17+
}
18+
}
19+
},
20+
async (commander, args) => {
21+
const [mode = 'build', pattern = path.join(config.projectDir, '**')] = args;
22+
23+
switch (mode) {
24+
case 'build':
25+
info(`Starting build vue app...`);
26+
27+
await multipleBuild(config, {
28+
cmd: commander.execute || 'vue-cli-service build --mode production',
29+
pattern
30+
});
31+
break;
32+
33+
case 'check':
34+
const { entries } = config.vueCli;
35+
36+
info(`Check entries for currentWebsite ${chalk.cyan(config.currentWebsite)}`);
37+
38+
entries.forEach(entry => {
39+
entry.paths.forEach(file => {
40+
if (!fs.existsSync(file)) {
41+
warn(`Entry is KO: ${chalk.red(file)}`);
42+
process.exit(-1);
43+
}
44+
});
45+
});
46+
47+
info(`Entries is ok for the currentWebsite ${chalk.cyan(config.currentWebsite)}`);
48+
break;
49+
50+
default:
51+
break;
52+
}
53+
}
54+
);
55+
};

packages/cli-plugin-vue/package-lock.json

Lines changed: 59 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli-plugin-vue/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
"@vue/cli-service": "^3.1.1",
1111
"@vue/cli-shared-utils": "^3.1.1"
1212
},
13-
"dependencies": {},
13+
"dependencies": {
14+
"gulp-tap": "^1.0.1"
15+
},
1416
"directories": {
1517
"src": "./src"
1618
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const path = require('path');
2+
const gulp = require('gulp');
3+
const tap = require('gulp-tap');
4+
const { info, chalk } = require('@vue/cli-shared-utils');
5+
const execa = require('execa');
6+
7+
module.exports = (config, options) =>
8+
gulp.src(options.pattern).pipe(
9+
tap(projectFolder => {
10+
const currentWebsite = path.basename(projectFolder.path);
11+
12+
try {
13+
execa.sync('nsc', ['vue', 'check', '--currentWebsite', currentWebsite], {
14+
shell: true,
15+
env: {
16+
FORCE_COLOR: true
17+
},
18+
stdio: 'inherit'
19+
});
20+
} catch (er) {
21+
return;
22+
}
23+
24+
info(`Start build Project ${chalk.cyan(currentWebsite)}`);
25+
26+
let cmd = `${options.cmd}${options.cmd.match(/^npm/) ? ' -- ' : ''} --currentWebsite ${currentWebsite}`;
27+
cmd = cmd.split(' ');
28+
29+
const task = cmd[0];
30+
const args = cmd.splice(1).filter(t => !!t);
31+
32+
execa.sync(task, args, {
33+
shell: true,
34+
env: {
35+
FORCE_COLOR: true
36+
},
37+
stdio: 'inherit'
38+
});
39+
})
40+
);

packages/cli-plugin-vue/src/webpack/build.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ module.exports = (config, baseVueConfig) => {
3333
} else {
3434
Object.keys(alias).forEach(key => {
3535
const search = new RegExp(key.replace(/@/, '~'), 'gi');
36-
info(search.toString());
3736
sass.data = sass.data.replace(search, alias[key]);
3837
});
3938
}

packages/cli/package-lock.json

Lines changed: 11 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)