Skip to content

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

@passchn

Description

@passchn

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions