Skip to content

Commit 247a9ff

Browse files
committed
feat(ncc): Add start a watched build.
1 parent c74fde1 commit 247a9ff

3 files changed

Lines changed: 19 additions & 5 deletions

File tree

example/bundle-node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"build": "npm run bundle && npm run bundle:min",
88
"bundle": "ncc build src/app.ts",
9-
"watch": "ncc start src/app.ts",
9+
"watch": "ncc watch src/app.ts",
1010
"bundle:min": "ncc build src/app.ts -m"
1111
},
1212
"repository": {

packages/ncc/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Outputs the `Node.js` compact build of `input.js` into `dist/input.js`.
3737
## Commands
3838

3939
```bash
40-
Usage: ncc [build] [input-file] [--help|h]
40+
Usage: ncc [build|watch] [input-file] [--help|h]
4141

4242
Displays help information.
4343

@@ -47,6 +47,8 @@ Options:
4747
--help, -h Displays help information.
4848
-o, --out [dir] Output directory for build (defaults to dist).
4949
-m, --minify Minify output.
50+
-t, --target Instructs webpack to target a specific environment (defaults to node14).
51+
-l, --library Output a library exposing the exports of your entry point. The parameter "--target=web" works.
5052
-s, --source-map Generate source map.
5153
-e, --external [mod] Skip bundling 'mod'. Can be used many times.
5254

@@ -55,7 +57,9 @@ Example:
5557
$ ncc build
5658
$ ncc build --out ./dist
5759
$ ncc build --minify
60+
$ ncc watch --minify
5861
$ ncc build src/app.ts
62+
$ ncc build --target web --library MyLibrary
5963
$ ncc build --source-map
6064
```
6165

packages/ncc/src/index.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import minimist from 'minimist';
33
import path from 'path';
44
import fs from 'fs-extra';
5-
import { BuildArgs, build } from 'kkt';
5+
import { BuildArgs, build, start } from 'kkt';
66
import { overridePaths } from 'kkt/lib/overrides/paths';
77
import { sync as gzipSize } from 'gzip-size';
88
import filesize from 'filesize';
@@ -11,7 +11,7 @@ import { filterPlugins, removeLoaders } from './utils';
1111

1212
function help() {
1313
const { version } = require('../package.json');
14-
console.log('\n Usage: \x1b[34;1mncc\x1b[0m [build] [input-file] [--help|h]');
14+
console.log('\n Usage: \x1b[34;1mncc\x1b[0m [build|watch] [input-file] [--help|h]');
1515
console.log('\n Displays help information.');
1616
console.log('\n Options:\n');
1717
console.log(' --version, -v ', 'Show version number');
@@ -32,6 +32,7 @@ function help() {
3232
console.log(' $ \x1b[35mncc\x1b[0m build');
3333
console.log(' $ \x1b[35mncc\x1b[0m build --out ./dist');
3434
console.log(' $ \x1b[35mncc\x1b[0m build --minify');
35+
console.log(' $ \x1b[35mncc\x1b[0m watch --minify');
3536
console.log(' $ \x1b[35mncc\x1b[0m build src/app.ts');
3637
console.log(` $ \x1b[35mncc\x1b[0m build --target web --library MyLibrary`);
3738
console.log(` $ \x1b[35mncc\x1b[0m build --source-map`);
@@ -125,6 +126,7 @@ process.on('exit', (code) => {
125126

126127
argvs.out = argvs.o = path.resolve(argvs.out || argvs.o || 'dist');
127128
argvs.minify = argvs.m = argvs.minify || argvs.m || false;
129+
// argvs.watch = argvs.w = argvs.watch || argvs.w || false;
128130

129131
const scriptName = argvs._[0];
130132
const inputFile = path.resolve(argvs._[1] || 'src/index.ts');
@@ -189,15 +191,23 @@ process.on('exit', (code) => {
189191
}
190192
return conf;
191193
};
194+
data.minify = argvs.minify;
192195
if (scriptName === 'build') {
193196
await build({
194197
...argvs,
195198
bundle: true,
196199
isNotCheckHTML: true,
197200
overridePaths: { ...oPaths },
198201
});
202+
} else if (scriptName === 'watch') {
203+
await start({
204+
...argvs,
205+
watch: true,
206+
bundle: true,
207+
isNotCheckHTML: true,
208+
overridePaths: { ...oPaths },
209+
});
199210
}
200-
data.minify = argvs.minify;
201211
} catch (error) {
202212
console.log('\x1b[31m KKT:NCC:ERROR:\x1b[0m', error);
203213
}

0 commit comments

Comments
 (0)