You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use Vite with PHP and I need some mechanism to check whether there's a dev server currently running. I can ping http://localhost:3000 with curl from within PHP, but I believe that's inefficient.
I think it'll be better to check for the existence of dist/manifest.json, since it has to be used anyways. If it exists, then just load the production files listed inside. Otherwise, consider that Vite is running in development mode and request the assets from http://localhost:3000.
Currently, that's not possible because the dist folder is removed only when you re-run the build command. If you run Vite in development mode, that folder remains and this manifest.json check can't work.
Suggested solution
Have a setting in vite.config.js that removes the dist folder always, not just on build. Something like build.clean with possible values:
"always": Remove the folder regardless of mode (solves this use case).
However, the manifest file should be deleted, if you start a dev server, so the new files are being used, as you wrote.
For that I use two scripts (in the scripts section) in my package.json:
"scripts": {
"del": "npx rimraf dist/site/templates/assets/js/manifest.json",
"dev": "npm run del && cross-env NODE_ENV=development vite",
"build": "npm run del && gulp && cross-env NODE_ENV=production vite build"
},
I agree with you, that a native option for this would be great and is needed.
The dev server doesn't output any files, so there's isn't anything to clear, so I'm a bit confused here. If the dist/manifest.json is generated somewhere externally, perhaps you can write a Vite plugin to auto delete that too. Closing as this is a userland issue.
Clear and concise description of the problem
I use Vite with PHP and I need some mechanism to check whether there's a dev server currently running. I can ping
http://localhost:3000
with curl from within PHP, but I believe that's inefficient.I think it'll be better to check for the existence of
dist/manifest.json
, since it has to be used anyways. If it exists, then just load the production files listed inside. Otherwise, consider that Vite is running in development mode and request the assets fromhttp://localhost:3000
.Currently, that's not possible because the
dist
folder is removed only when you re-run thebuild
command. If you run Vite in development mode, that folder remains and thismanifest.json
check can't work.Suggested solution
Have a setting in
vite.config.js
that removes thedist
folder always, not just onbuild
. Something likebuild.clean
with possible values:"always"
: Remove the folder regardless of mode (solves this use case)."production"
: Current behavior.false
: Never clean the folder. Can be useful for cases like this Add option to stop build removing dist directory vuejs/vue-cli#1446.Alternative
A command line option like
--clear-dev
could also do the job.Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: