I have a situation where I am bundling multiple files via rollup cli
an example of this is available in documentation.
I export an array of bundles like so:
export default [
{
input: 'packages/A/index.js',
output: {
name: '[name]Bundle',
file: '[name].umd.js',
format: 'umd'
}
},
{
input: 'packages/B/index.js',
output: {
name: '[name]Bundle',
file: '[name].umd.js',
format: 'umd'
}
}
];
And then I have a function that adds a common config to each bundle (think plugins) so something like:
import path from "path";
import alias from '@rollup/plugin-alias';
import resolve from '@rollup/plugin-node-resolve';
const augment = configs => {
const generateAlias = (symbol, location) => {
return {
find: symbol,
replacement: path.resolve(process.cwd(), location)
};
}
const entries = [
generateAlias("@", "src/"),
generateAlias("~", "src/assets/scss/"),
generateAlias("#", "src/assets/img/"),
generateAlias("%", "config/"),
];
const plugins = [
alias({
entries
}),
resolve({ browser: true }),
];
return configs.map(entry => {
return {
...entry,
plugins
}
});
}
export {
augment
}
And the I wrap the above exported array in augment
like:
const bundles = [/* above example */];
export default augment(bundles);
Now this all works fine, but I have two plugins that I don't actually want to apply to each bundle I just want to run them once all the bundles have built, those two plugins are; rollup-plugin-serve and rollup-plugin-workbox now neither of these actually have anything to do with any of the files being bundled, and make no sense to instantiate more than once.
What I would like to do as part of the augment
function to to append them to the end of the returned array something like:
const exportedArray = configs.map(/* function from above */);
exportedArray.push(...[
{
plugins: [
serve({
host,
port,
contentBase: 'dist/'
})
]
}
]);
return exportedArray;
And this would not contain an input
, I have tried the above and rollup complains, the alternative option would be to add these plugins to the final bundle on the array, I just prefer the idea of instantiating them without them being tied to a particular bundle.