diff --git a/e2e/rollup/src/rollup.test.ts b/e2e/rollup/src/rollup.test.ts index edc841a4fc..bd4f2be887 100644 --- a/e2e/rollup/src/rollup.test.ts +++ b/e2e/rollup/src/rollup.test.ts @@ -210,4 +210,30 @@ export default config; checkFilesExist(`libs/test/dist/bundle.js`); checkFilesExist(`libs/test/dist/bundle.es.js`); }); + + it('should support array config from rollup.config.js', () => { + const jsLib = uniq('jslib'); + runCLI(`generate @nx/js:lib ${jsLib} --bundler rollup`); + updateFile( + `libs/${jsLib}/rollup.config.js`, + `module.exports = (config) => [{ + ...config, + output: { + format: "esm", + dir: "dist/test", + name: "Mylib", + entryFileNames: "[name].js", + chunkFileNames: "[name].js" + } + }]` + ); + updateJson(join('libs', jsLib, 'project.json'), (config) => { + config.targets.build.options.rollupConfig = `libs/${jsLib}/rollup.config.js`; + return config; + }); + + expect(() => runCLI(`build ${jsLib} --format=esm`)).not.toThrow(); + + checkFilesExist(`dist/test/index.js`); + }); }); diff --git a/packages/rollup/src/executors/rollup/rollup.impl.ts b/packages/rollup/src/executors/rollup/rollup.impl.ts index 1678866859..cef1e0f30c 100644 --- a/packages/rollup/src/executors/rollup/rollup.impl.ts +++ b/packages/rollup/src/executors/rollup/rollup.impl.ts @@ -118,13 +118,17 @@ export async function* rollupExecutor( } const start = process.hrtime.bigint(); - const bundle = await rollup.rollup(rollupOptions); - const output = Array.isArray(rollupOptions.output) - ? rollupOptions.output - : [rollupOptions.output]; + const allRollupOptions = Array.isArray(rollupOptions) + ? rollupOptions + : [rollupOptions]; - for (const o of output) { - await bundle.write(o); + for (const opts of allRollupOptions) { + const bundle = await rollup.rollup(opts); + const output = Array.isArray(opts.output) ? opts.output : [opts.output]; + + for (const o of output) { + await bundle.write(o); + } } const end = process.hrtime.bigint(); @@ -150,7 +154,7 @@ export async function createRollupOptions( packageJson: PackageJson, sourceRoot: string, npmDeps: string[] -): Promise { +): Promise { const useBabel = options.compiler === 'babel'; const useTsc = options.compiler === 'tsc'; const useSwc = options.compiler === 'swc'; @@ -287,7 +291,7 @@ export async function createRollupOptions( const userDefinedRollupConfigs = options.rollupConfig.map((plugin) => loadConfigFile(plugin) ); - let finalConfig: rollup.InputOptions = rollupConfig; + let finalConfig: rollup.RollupOptions = rollupConfig; for (const _config of userDefinedRollupConfigs) { const config = await _config; if (typeof config === 'function') {