-
-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Copy files to public folder on change when watching #36
Comments
Would you expand this? Also I guess you also need to copy files when the dev server starts. |
Indeed, a copy on server start would be a good idea. |
@sapphi-red I made a Pull request for this option. #37 |
Would you expand this first? Copying a file during dev is currently out of scope of this plugin. |
So we refer to the public files from within PHP templates with absolute paths. And when in watch mode, it would be easy if these files get copied on change, so we don't have to quit the watch and run a build to get them into the public folder. The changes I've made in the pull request do exactly that. And it works fine. So if you agree, then you can merge the pull request. |
Are you directly reading those files from PHP (e.g. replacing text) and not simply referring in the rendered HTML? If you just need to refer it, you can just use the file like export default {
plugins: [
viteStaticCopy({
targets: [
{
src: 'images/sample.jpg',
dest: 'foo/bar'
}
]
})
]
} |
Exactly. |
Then, why do you need to copy the files? I think it's easier to just read the original files. |
Because we try to keep production files and the dev file separate. So the site reads from the production public folder, but we add the files in the dev folder. And we then use this plugin to copy them over to the public folder. So the website code expects the files in the public folder. But we do not put them in directly, hence the copy. If everybody would just put their files in the public folder, this plugin would be obsolete, no? Have you had a chance to review my pull request? And do you have arguments, not to expand the scope of the plugin with this option? |
I see. Thanks for explaining.
Yes, I encourage that and documented that. I think the only case this plugin is needed is to use files in npm packages that needs to be served in a specific path.
I've considered again but it's still out of scope of this plugin. This plugin follows the way Vite works: no bundling/copying when dev. |
Ok @sapphi-red I understand your point. If ever it gets in, please comment on this thread. |
I just ported my whole project from Gulp to Vite and this is the only step missing to make it complete. I work in a Wordpress environment and even in development the images get reverenced in the dist folder (I would love doing some post processing on the assets, but for now just copying them would be great). Any plans to just make this an option when running dev? |
Yep its a major glaring hole in Vite and related plugins like this. "Stick it in public" refrains are just braindead. public is the build, developers keep source files outside of the build until runtime - either a watch or a build step. Why is this plugin ever needed if developers should just toss everything in public? |
I also encountered the same requirement and found that "rollup-copy-plugin" can be used as a substitute. I hope this can help those who need it . import copy from "rollup-plugin-copy";
export default defineConfig({
plugins: [
copy({
copyOnce: true,
verbose: true,
copySync: true,
hook: "buildStart",
targets: [
{
src: "src",
dest: "dest",
},
],
}),
],
}); |
You can now already do
watch: { reloadPageOnChange: true }
But in the system I'm using I refer to the files in the dest folder with a serverpath not a URL.
So it would be nice to have an option to also copy the file on change and then reload the page.
Something like:
The text was updated successfully, but these errors were encountered: