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

inline: false and external: [] causes invalid syntax with multiple outputs #64

Open
mattrossman opened this issue Jul 16, 2022 · 1 comment · May be fixed by #65
Open

inline: false and external: [] causes invalid syntax with multiple outputs #64

mattrossman opened this issue Jul 16, 2022 · 1 comment · May be fixed by #65

Comments

@mattrossman
Copy link

Given this rollup configuration:

import webWorker from "rollup-plugin-web-worker-loader";

/** @type {import('rollup').RollupOptions} */
export default {
    input: "src/index.js",
    output: [
        {
            file: "dist/index.js",
            format: "cjs",
        },
        {
            file: "dist/index.modern.js",
            format: "es",
        },
    ],
    plugins: [
        webWorker({
            targetPlatform: "browser",
            inline: false,
            external: [],
        }),
    ],
};

This plugin tries to write both rollup outputs to the same destination index.modern.js. This results in a file that is a mixture of CJS and ESM, an invalid syntax that causes errors.

It seems this is because the plugin holds a single mutable filename reference in state.configuredFileName

const state = {
idMap: new Map(),
exclude: new Set(),
outFiles: new Map(),
options: null,
basePath: null,
forceInlineCounter: 0,
configuredFileName: null,
};

This mutable value is used as the output destination, which is unstable.

function outputOptions(state, config, options) {
if (!config.inline && options.file && !options.dir) {
state.configuredFileName = path.basename(options.file);
return Object.assign({}, options, {
file: null,
dir: path.dirname(options.file),
});
}
return null;
}

I will try to make a PR fix.

@mattrossman
Copy link
Author

Not familiar with writing rollup plugins but I find it strange that options.file is null in generateBundle but not in outputOptions. It seems difficult to lookup the original configured file value for each output in the generateBundle phase. The only unique data I can see is the options.format. I can't remember if rollup lets you define multiple outputs with the same format, but for now I will just pretend each format is a unique output so I can look up the file name from a Map.

@mattrossman mattrossman linked a pull request Jul 16, 2022 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant