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

outputOptions hook does not allow to switch dir and file #2801

Closed
darionco opened this issue Apr 10, 2019 · 1 comment · Fixed by #2802
Closed

outputOptions hook does not allow to switch dir and file #2801

darionco opened this issue Apr 10, 2019 · 1 comment · Fixed by #2802

Comments

@darionco
Copy link

  • Rollup Version: 1.9.0
  • Operating System (or Browser): OSX Mojave - 10.14.4
  • Node Version: v11.13.0

How Do We Reproduce?

in plugin:

const newChunk = ...; // generate custom chunk
// ...
generateBundle(options, bundle, isWrite) {
    if (isWrite && newChunk && !bundle[newChunk.fileName]) {
        bundle[newChunk.fileName] = newChunk;
    }
},
// ...
outputOptions(options) {
    if (options.file && !options.dir) {
        return Object.assign({}, options, {
            file: null,
            dir: path.dirname(options.file),
        });
    }
    // console.log(options);
    return null;
}

Expected Behavior

Rollup writes the chunks as files in the specified folder.

Actual Behavior

Rollup exits with the following error:

Error: When building multiple chunks, the "output.dir" option must be used, not "output.file". To inline dynamic imports, set the "inlineDynamicImports" option.

Explanation

I am building a web worker loader plugin, it already has the ability to inline the worker code, but I would also like to provide the option to emit a worker script file that is loaded at runtime.

The way the worker code is bundled right now is by using Rollup's JS interface within the plugin to build the worker code as a new module. At the end of this process I get a chunk with the code that I can then inspect and inject to inline the Worker, to emit a worker script file the easiest solution is to add the resulting chunk to the bundle in the generateBundle hook and let rollup write the file.

If the original outputOptions object already uses output.dir everything works as expected, but Rollup won't allow me to switch output.file for output.dir as demonstrated in the code above.

@lukastaegert
Copy link
Member

Fix at #2802

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

Successfully merging a pull request may close this issue.

2 participants