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

build.emptyOutDir not working with modules/dynamic imports #8

Open
passchn opened this issue Jan 22, 2023 · 4 comments
Open

build.emptyOutDir not working with modules/dynamic imports #8

passchn opened this issue Jan 22, 2023 · 4 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@passchn
Copy link
Collaborator

passchn commented Jan 22, 2023

Vite config:

build: {
        emptyOutDir: true,
        outDir: './webroot/dist',
        manifest: true,
        rollupOptions: {
            input: {
                main: './webroot_src/main.ts',
            },
        },
    },

Generated html:
out-dir-bug

The green scripts are inserted by the plugin, but the red above come from vite. Vite expects the outDir to be the root which is accessible by apache etc.

So there is no /dist prefix and dynamic modules cannot be loaded.

A solution would be to set outDir to ./webroot. But then, vite will remove all files in webroot if emptyOutDir is true.

Does anyone have an idea how to fix that? If not, emptyOutDir would not work if you have static assets in webroot that don't come from vite.

You would have to delete the /assets folder before building manually here and there (not a big deal though).

@passchn passchn added help wanted Extra attention is needed enhancement New feature or request labels Jan 22, 2023
@t0byman
Copy link

t0byman commented Jan 22, 2023

Maybe load the those (legacy) plugins scripts in a vite script entry instead of through ViteScripts->script ?

@passchn
Copy link
Collaborator Author

passchn commented Jan 22, 2023

The legacy scripts are correctly loaded (green -> correct).

The problem is with the init-cart stuff (red border, above) which comes from an es module. It is loaded dynamically and inserted via javascript.

As you see, the url begins with /assets instead of /dist/assets.

@passchn
Copy link
Collaborator Author

passchn commented Jan 22, 2023

This is because the outDir in vite is set to ./webroot/dist and, therefore, vite seems to expect that dist/ is kind of my root on the domain.

@bor-attila
Copy link
Contributor

How the init-cart.css comes into the play?
The ./webroot_src/main.ts imports something what imports the init-cart.css ? Where the init-cart.css is located ?

Also there is a root option in vite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Development

No branches or pull requests

3 participants