Skip to content

Commit fdaa007

Browse files
committed
feat: mars build support watch mode
1 parent 857f076 commit fdaa007

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

packages/mars-cli/bin/mars-build.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ program
1313
.description('build project in production mode')
1414
.option('-r, --registry <url>', 'Use specified npm registry when installing dependencies (only for npm)')
1515
.option('-t, --target <target>', 'Build target (swan | h5 | wx, default: swan)')
16+
.option('-w, --watch', 'Open watch mode')
1617
.action(cmd => {
1718
const build = require('../lib/build');
1819
const options = cleanArgs(cmd);

packages/mars-cli/bin/mars.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ program
148148
.description('build project in production mode')
149149
.option('-r, --registry <url>', 'Use specified npm registry when installing dependencies (only for npm)')
150150
.option('-t, --target <target>', 'Build target (swan | h5 | wx, default: swan)')
151+
.option('-w, --watch', 'Open watch mode')
151152
.action(cmd => {
152153
const options = cleanArgs(cmd);
153154
const buildPath = path.resolve(__dirname, './mars-build.js');

packages/mars-cli/lib/build.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,21 @@ async function build(cmd) {
1515

1616
const {
1717
build,
18+
watch,
1819
clean
1920
} = require(buildPath);
2021

2122
const options = {
22-
target,
23-
build: true
23+
target
2424
};
2525
process.env.NODE_ENV = 'production';
2626
process.env.MARS_CLI_OPTIONS = JSON.stringify(options);
2727
process.env.MARS_CLI_TARGET = target;
2828

29+
const run = cmd.watch ? watch : build;
30+
2931
clean(options).once('stop', () => {
30-
build(options).once('stop', () => {
32+
run(options).once('stop', () => {
3133
if (target === 'h5') {
3234
const child = execa('npm', ['run', 'build-dist-h5']);
3335
child.stdout.pipe(process.stdout);

0 commit comments

Comments
 (0)