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

Can't pass an array into output option in rollup config #3411

Closed
Kirpich634 opened this issue Feb 28, 2020 · 3 comments
Closed

Can't pass an array into output option in rollup config #3411

Kirpich634 opened this issue Feb 28, 2020 · 3 comments

Comments

@Kirpich634
Copy link

Kirpich634 commented Feb 28, 2020

Expected Behavior

Will get two files 'lib/kek.js' and 'es/kek.js'

Actual Behavior

npm run build

> @ build /Users/kirpich634/Projets/rollup-keker
> node build.js

(node:15616) UnhandledPromiseRejectionWarning: Error: You must specify "output.file" or "output.dir" for the build.
    at error (/Users/kirpich634/Projets/rollup-keker/node_modules/rollup/dist/shared/node-entry.js:5400:30)
    at Object.write (/Users/kirpich634/Projets/rollup-keker/node_modules/rollup/dist/shared/node-entry.js:13981:28)
    at rollup.then.bundle (/Users/kirpich634/Projets/rollup-keker/build.js:7:12)

According to the documentation, we can put an array inside an output option
#3184
Снимок экрана 2020-02-29 в 00 22 11

I've tried to localize the root of the problem in the rollup index: https://github.com/rollup/rollup/blob/master/src/rollup/index.ts

It seems that in normalizeOutputOptions function we always pass config.output into the mergeOptions as an object instead of an array:

normalizeOutputOptions:

	const mergedOptions = mergeOptions({
		config: {
			output: {
				...rawOutputOptions,
				...(rawOutputOptions.output as object),
				...(inputOptions.output as object)
			}
		}
	});

mergeOptions:

export default function mergeOptions({
	config = {},
        ...
} {
	....
	const output = config.output;
	const normalizedOutputOptions = Array.isArray(output) ? output : output ? [output] : [];

I do not understand why you do this:

config: {
	...rawOutputOptions,
	...(rawOutputOptions.output as object),
	...(inputOptions.output as object)
}

Can we do something like this ??

config: {
	output: rawOutputOptions		
}
@lukastaegert
Copy link
Member

No, because this is not supported when using the JS API and is also not intended to be supported. You have been looking at the documentation for config files, not the documentation for the JS API. When directly using the JS API, the idea is that you just call bundle.generate or bundle.write once for each output.

@lukastaegert
Copy link
Member

The reason we do the strange merge is because at some point, passing input options as output options was done by some tools even though it is not intended to work this way. By specification, you should pass a single outputOptions object to bundle.write and nothing else

@Kirpich634
Copy link
Author

Thank you for your help.

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

No branches or pull requests

2 participants