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

Include publicDir: false in vite.config.js #17

Closed
marcelkorpel opened this issue Apr 6, 2022 · 4 comments
Closed

Include publicDir: false in vite.config.js #17

marcelkorpel opened this issue Apr 6, 2022 · 4 comments

Comments

@marcelkorpel
Copy link

When building a project for deployment I run npm run build, which runs vite build. By default, Vite will copy all assets in /public to the build directory. However, this is generally not what you want with the Symfony /public directory: apart from useless files like index.php it will also copy bundles in /public/bundles, so a directory is created. At this moment, you will run into trouble with npm run dev, which outputs:

error when starting dev server:
SystemError [ERR_FS_EISDIR]: Path is a directory: rm returned EISDIR (is a directory) /Users/xxx/Sites/project-dir/public/build/bundles

You can circumvent this whole copying behaviour by adding

publicDir: false

to vite.config.js.

Would this be a sane default to add to the README?

@svondervoort
Copy link

svondervoort commented Jun 22, 2022

It's weird I don't see the index.php being copied into the build folder. I also have a public/resources folder which does get copied to build/resources.

I get the same error. Seems like vite build isn't expecting a folder to be within the build folder.

@svondervoort
Copy link

svondervoort commented Jun 22, 2022

Just a small update, I currently updated the scripts in package.json to first remove the build folder and then run vite.

    "scripts": {
        "dev": " rm -rf public/build && vite",
        "build": "vite build"
    },

Seems to work.

@lhapaipai
Copy link
Owner

Thank you @marcelkorpel, You're totally right !

@lhapaipai
Copy link
Owner

for your information, I added a new feature to vite-plugin-symfony v0.5.2. Vite will serve files in public directory as static files but will not copy public directory in build process. so we can enjoy the files present in public dir without its side effects.
if you don't wants this feature you can set : symfonyPlugin({ servePublic: false })

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