Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function greeting(name: string) {
return `Hello ${name}`;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "pack-watch-config",
"private": true,
"type": "module"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[[case]]
name = "pack_watch_reloads_config"
vp = "local"
comment = "Changing pack.minify while watching applies the new configuration, including on Windows."
steps = [["node", "verify.mjs"]]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# pack_watch_reloads_config

Changing pack.minify while watching applies the new configuration, including on Windows.

## `node verify.mjs`

```
pack --watch applied the updated minify option
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import assert from 'node:assert/strict';
import { fork } from 'node:child_process';
import { once } from 'node:events';
import { readFile, readdir, writeFile } from 'node:fs/promises';
import { createRequire } from 'node:module';
import { dirname, join } from 'node:path';

const require = createRequire(import.meta.url);
const cli = join(dirname(require.resolve('vite-plus/package.json')), 'dist/pack-bin.js');
const child = fork(cli, ['--watch'], { silent: true });
let logs = '';
child.stdout.on('data', (data) => {
logs += data;
});
child.stderr.on('data', (data) => {
logs += data;
});

try {
// The onSuccess IPC message synchronizes edits with completed builds on every platform.
await once(child, 'message', { signal: AbortSignal.timeout(20000) });
const output = join('dist', (await readdir('dist')).find((file) => /\.m?js$/.test(file)));
const before = await readFile(output, 'utf8');
assert.match(before, /\n/);

const rebuilt = once(child, 'message', { signal: AbortSignal.timeout(20000) });
const config = await readFile('vite.config.ts', 'utf8');
await writeFile('vite.config.ts', config.replace('minify: false', 'minify: true'));
await rebuilt;

const after = await readFile(output, 'utf8');
assert.notEqual(after, before, 'the rebuilt output must use the updated pack configuration');
assert.ok(
after.trim().split('\n').length < before.trim().split('\n').length,
'the rebuilt output must be minified',
);
console.log('pack --watch applied the updated minify option');
} catch (error) {
console.error(logs);
throw error;
} finally {
if (child.exitCode === null && child.signalCode === null) {
const exited = once(child, 'exit');
child.kill();
await exited;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default {
pack: {
entry: ['index.ts'],
dts: false,
minify: false,
onSuccess() {
process.send?.('built');
},
},
};
4 changes: 3 additions & 1 deletion packages/cli/src/pack-bin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env node
import module from 'node:module';
import path from 'node:path';

import { cac } from 'cac';
import {
Expand Down Expand Up @@ -155,7 +156,8 @@ cli

const configDeps = new Set<string>();
if (viteConfig?.configFile) {
configDeps.add(viteConfig.configFile);
// Vite uses forward slashes, but watcher events use native path separators.
configDeps.add(path.normalize(viteConfig.configFile));
}

const configs: ResolvedConfig[] = [];
Expand Down
Loading