Skip to content

Commit 64feae0

Browse files
committed
feat: add write option
1 parent bcbf12b commit 64feae0

File tree

6 files changed

+16
-7
lines changed

6 files changed

+16
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"lint": "eslint --cache --max-warnings 0 .",
5050
"lint:fix": "pnpm run lint --fix",
5151
"build": "unrun ./src/run.ts",
52-
"dev": "unrun ./src/run.ts",
52+
"dev": "node ./src/run.ts",
5353
"test": "vitest",
5454
"typecheck": "tsc --noEmit",
5555
"format": "prettier --cache --write .",

src/cli.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ cli
3434
.option('--target <target>', 'Bundle target, e.g "es2015", "esnext"')
3535
.option('-l, --logLevel <level>', 'Set log level: info, warn, error, silent')
3636
.option('--fail-on-warn', 'Fail on warnings', { default: true })
37+
.option(
38+
'--no-write',
39+
'Disable writing files to disk, incompatible with watch mode',
40+
)
3741
.option('-d, --out-dir <dir>', 'Output directory', { default: 'dist' })
3842
.option('--treeshake', 'Tree-shake bundle', { default: true })
3943
.option('--sourcemap', 'Generate source map', { default: false })

src/config/options.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export async function resolveUserConfig(
7777
inlineOnly,
7878
fixedExtension = platform === 'node',
7979
debug = false,
80+
write = true,
8081
} = userConfig
8182

8283
const pkg = await readPackageJson(cwd)
@@ -238,6 +239,7 @@ export async function resolveUserConfig(
238239
unbundle,
239240
unused,
240241
watch,
242+
write,
241243
}
242244

243245
return config

src/config/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,12 @@ export interface UserConfig {
259259
globalName?: string
260260
/** @default 'dist' */
261261
outDir?: string
262+
/**
263+
* Whether to write the files to disk.
264+
* This option is incompatible with watch mode.
265+
* @default true
266+
*/
267+
write?: boolean
262268
/**
263269
* Whether to generate source map files.
264270
*

src/features/rolldown.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export async function getBuildOptions(
5959
const rolldownConfig: BuildOptions = {
6060
...inputOptions,
6161
output: outputOptions,
62+
write: config.write,
6263
}
6364
debug(
6465
'rolldown config with format "%s" %O',

src/index.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,8 @@ export async function build(
8181
for (const bundle of bundles) {
8282
disposeCbs.push(bundle[asyncDispose])
8383
}
84-
85-
return undefined as never
86-
}
87-
88-
// build done
89-
if (firstDevtoolsConfig) {
84+
} else if (firstDevtoolsConfig) {
85+
// build done, start devtools
9086
const { start } = await importWithError<
9187
typeof import('@vitejs/devtools/cli-commands')
9288
>('@vitejs/devtools/cli-commands')

0 commit comments

Comments
 (0)