Things I want to do
This will automatically execute a custom batch file when building (using npm run build) in Vite.
Specific example
The following tasks could be automated to be useful. (There are probably many other things, but these are the ones that immediately come to mind.)
- Lightweight SVG
- Add copyright to JS file
- Copy from distribution to production environment
setting
Open the package.json file located in the root directory of your Vite project.
I believe the following description is included.
"scripts": {
"dev": "node log.js dev & vite --config vite/config.dev.mjs",
"build": "node log.js build & vite build --config vite/config.prod.mjs",
"dev-nolog": "vite --config vite/config.dev.mjs",
"build-nolog": "vite build --config vite/config.prod.mjs"
},This article adds processing when you run ‘npm run build’, so modify the line ‘build’: ‘node log.js build & vite build –config vite/config.prod.mjs’,
Before revision:
"build": "node log.js build & vite build --config vite/config.prod.mjs",After correction:
"build": "node log.js build & vite build --config vite/config.prod.mjs & call CustomBuild.bat",The above modification will ensure that CustomBuild.bat is executed after the vite build. The path to the bat file is relative to the project root. The example above assumes that CustomBuild.bat is located in the root directory.
The current folder within a batch file is the project root. Be careful when using relative paths within a batch file.
Result
I was able to configure npm run build to execute an additional batch file when building.


コメント