diff --git a/readme.md b/readme.md index 8c9a261d..fed18534 100644 --- a/readme.md +++ b/readme.md @@ -61,6 +61,8 @@ Outputs the Node.js compact build of `input.js` into `dist/index.js`. -m, --minify Minify output -C, --no-cache Skip build cache population -s, --source-map Generate source map + -a, --asset-builds Build nested JS assets recursively, useful for + when code is loaded as an asset eg for workers. --no-source-map-register Skip source-map-register source map support -e, --external [mod] Skip bundling 'mod'. Can be used many times -q, --quiet Disable build summaries / non-error outputs @@ -115,6 +117,7 @@ require('@vercel/ncc')('/path/to/input', { filterAssetBase: process.cwd(), // default minify: false, // default sourceMap: false, // default + assetBuilds: false, // default sourceMapBasePrefix: '../', // default treats sources as output-relative // when outputting a sourcemap, automatically include // source-map-support in the output file (increases output by 32kB). diff --git a/src/cli.js b/src/cli.js index bb8d4580..291860aa 100755 --- a/src/cli.js +++ b/src/cli.js @@ -128,6 +128,8 @@ async function runCmd (argv, stdout, stderr) { let args; try { args = require("arg")({ + "--asset-builds": Boolean, + '-a': '--asset-builds', "--debug": Boolean, "-d": "--debug", "--external": [String], @@ -240,7 +242,7 @@ async function runCmd (argv, stdout, stderr) { externals: args["--external"], sourceMap: args["--source-map"] || run, sourceMapRegister: args["--no-source-map-register"] ? false : undefined, - noAssetBuilds: args["--no-asset-builds"] ? true : false, + assetBuilds: args["--asset-builds"] ? true : false, cache: args["--no-cache"] ? false : undefined, watch: args["--watch"], v8cache: args["--v8-cache"], diff --git a/src/index.js b/src/index.js index 3a9ada32..47763590 100644 --- a/src/index.js +++ b/src/index.js @@ -44,7 +44,7 @@ function ncc ( sourceMap = false, sourceMapRegister = true, sourceMapBasePrefix = '../', - noAssetBuilds = false, + assetBuilds = false, watch = false, v8cache = false, filterAssetBase = process.cwd(), @@ -564,7 +564,7 @@ function ncc ( } // for each .js / .mjs / .cjs file in the asset list, build that file with ncc itself - if (!noAssetBuilds) { + if (assetBuilds) { const compilation = compilationStack[compilationStack.length - 1]; let existingAssetNames = Object.keys(assets); existingAssetNames.push(`${filename}${ext === '.cjs' ? '.js' : ''}`); @@ -595,7 +595,7 @@ function ncc ( sourceMapBasePrefix, // dont recursively asset build // could be supported with seen tracking - noAssetBuilds: true, + assetBuilds: false, v8cache, filterAssetBase, existingAssetNames, diff --git a/test/cli.js b/test/cli.js index 84858c8a..7042173c 100644 --- a/test/cli.js +++ b/test/cli.js @@ -12,7 +12,7 @@ expect: { code: 0 } }, { - args: ["build", "test/fixtures/type-module/main.js", "-o", "tmp"], + args: ["build", "test/fixtures/type-module/main.js", "-a", "-o", "tmp"], expect: { code: 0 } }, { @@ -22,7 +22,7 @@ } }, { - args: ["run", "--v8-cache", "test/integration/test.ts"], + args: ["run", "--v8-cache", "-a", "test/integration/test.ts"], expect: { code: 0 } }, { @@ -44,7 +44,7 @@ } }, { - args: ["run", "--watch", "test/integration/test.ts"], + args: ["run", "--watch", "-a", "test/integration/test.ts"], expect: { code: 2 } }, { diff --git a/test/integration.test.js b/test/integration.test.js index 19d026ba..52d81bec 100644 --- a/test/integration.test.js +++ b/test/integration.test.js @@ -44,7 +44,7 @@ for (const integrationTest of fs.readdirSync(__dirname + "/integration")) { const stdout = new StoreStream(); const stderr = new StoreStream(); try { - await nccRun(["run", "--no-cache", "--no-asset-builds", `${__dirname}/integration/${integrationTest}`], stdout, stderr); + await nccRun(["run", "--no-cache", `${__dirname}/integration/${integrationTest}`], stdout, stderr); } catch (e) { if (e.silent) { diff --git a/test/unit.test.js b/test/unit.test.js index 11f4f40f..ffc6ec46 100644 --- a/test/unit.test.js +++ b/test/unit.test.js @@ -34,6 +34,7 @@ for (const unitTest of fs.readdirSync(`${__dirname}/unit`)) { // find the name of the input file (e.g input.ts) const inputFile = fs.readdirSync(testDir).find(file => file.includes("input")); await ncc(`${testDir}/${inputFile}`, Object.assign({ + assetBuilds: true, transpileOnly: true, customEmit (path) { if (path.endsWith('test.json')) diff --git a/test/watcher.test.js b/test/watcher.test.js index e071c490..f1280bd7 100644 --- a/test/watcher.test.js +++ b/test/watcher.test.js @@ -115,6 +115,7 @@ it('Should support custom watch API', async () => { console.time('First Build'); const { handler, rebuild, close } = ncc(buildFile, { + assetBuilds: true, watch: watcher });