I would like to run a script (e.g. to generate DTOs into /dist
necessary for build phase) defined in package.json
before each vite build and used buildStart hook as follows:
<code>// vite.config.ts
export default defineConfig({
// ...
plugins: [
{
name: 'run-script',
enforce: 'pre',
async buildStart() {
console.log('Running script...');
execSync('npm run custom-script');
console.log('Running script completed!');
},
},
],
// ...
});
</code>
<code>// vite.config.ts
export default defineConfig({
// ...
plugins: [
{
name: 'run-script',
enforce: 'pre',
async buildStart() {
console.log('Running script...');
execSync('npm run custom-script');
console.log('Running script completed!');
},
},
],
// ...
});
</code>
// vite.config.ts
export default defineConfig({
// ...
plugins: [
{
name: 'run-script',
enforce: 'pre',
async buildStart() {
console.log('Running script...');
execSync('npm run custom-script');
console.log('Running script completed!');
},
},
],
// ...
});
This actually works, except build.emptyOutDir option cleans up generated DTOs each time the outDir
/dist
, which is useful and I would like to keep emptyOutDir
option.
Is there any option to run a custom script before each vite build
but right after emptyOutDir
?