Skip to content
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

Not working well in a Laravel project using Vite #68

Open
Morinohtar opened this issue Sep 15, 2022 · 2 comments
Open

Not working well in a Laravel project using Vite #68

Morinohtar opened this issue Sep 15, 2022 · 2 comments

Comments

@Morinohtar
Copy link

Morinohtar commented Sep 15, 2022

Using

  • Laravel v9.30
  • vite v3.1.0
  • rollup-plugin-copy v3.4.0

Issue

I'm using the plugin in a Laravel project with Vite.

I have this part of code inserted in the vite.config.js file:

copy({ 
  targets: [{
      src: 'resources/themes/xpto',
      dest: 'public/build/assets'
  }],
  flatten: true,
  copyOnce: true,
  verbose: true,
}),

When i run the command npm run dev the plugin seems to not do anything, nothing is copied, but then if i change something in the vite.config.js file the vite watcher executes again automatically and this time the plugin works as expected and the folder is copied:

[vite] vite.config.js changed, restarting server...
copied:

  /var/www/html/resources/themes/xpto→ /var/www/html/public/build/assets/xpto
[vite] server restarted.

So far i haven't figured out how to make it work at first instruction. I tried a couple different hooks too, but to no avail.

Any ideas? Thanks.

@alexlafroscia
Copy link

alexlafroscia commented Jan 20, 2023

I ran into this as well, but was able to work around it with the right hook value.

What I observed was that upon starting the Vite dev server, nothing was copied, but once I killed the process the files would be copied. Upon looking further into the way that this package works, this makes sense, as it defaults to writing the files on buildEnd. This seems to be called when the process is killed.

If I set the hook to "buildStart", however, the files are copied at the point that the server starts.

So, I have a configuration like this, which seems to be working as I would expect it to!

import * as path from "node:path";
import copy from "rollup-plugin-copy";

/** @type {import('vite').UserConfig} */
export default {
  plugins: [
    copy({
      targets: [
        {
          src: path.resolve(__dirname, "path/to/thing"),
          dest: path.resolve(__dirname, "public/path/to/thing"),
        },
      ],
      hook: "buildStart",
      copyOnce: true,
    }),
  ],
};

@cora-li
Copy link

cora-li commented Sep 14, 2023

Hello everyone, I am also facing the same problem now.

Firstly, I strongly agree with alexlafroscia's view. Through my observation, I found that the buildStart and buildEnd hooks were executed too early, so that the chunks module that was later executed would empty the output folder. You can change the hook of the copy plugin to closeBundle to solve this problem. That's right, that's what I'm doing now. It works very well!

copy({
  hook: "closeBundle",
  targets: [
    { src: './dll/*', dest: 'dist/dll' },
  ]
}),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants