Skip to content

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

@darionco

Description

@darionco
  • 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions