An experimental bundle splitter plugin for Rollup
Last updated 2 years ago by emmiep .
MIT · Repository · Original npm · Tarball · package.json
$ cnpm install @emmiep/rollup-plugin-split-bundle 
SYNC missed versions from official npm registry.


Experimental Rollup plugin to split the code into separate bundles, for instance to create a "vendor bundle" with external npm packages. This is not code splitting for asynchronous loading with dynamic imports, such as using webpack and and import(). Use on your own risk, not tested and not recommended for production code!



npm install @emmiep/rollup-plugin-split-bundle

The plugin requires two rollup configurations, one for the main bundle (the "consumer" side) and one for the split bundle (the "producer" side).

First, use the consumer() plugin in the main bundle configuration (rollup.main.js):

import splitBundle from '@emmiep/rollup-plugin-split-bundle';

export default {
  input: 'src/index.js'
  output: {
    file: 'dist/app.js'
    format: 'umd',
    name: 'app'
  plugins: [
      name: '__vendor',
      modules: [

Then, use producerFromConfig() in the split bundle configuration (rollup.vendor.js) with the main bundle configuration:

import splitBundle from '@emmiep/rollup-plugin-split-bundle';
import mainConfig from './rollup.main';

export default {
  output: {
    file: 'dist/vendor.js'
    format: 'umd',
    name: 'vendor'
  plugins: [

Then invoke rollup with both configuration files:

rollup -c rollup.main.js
rollup -c rollup.vendor.js


The idea behind the plugin is straightforward and can easily be done manually as well.

The consumer prevents the listed modules from being included in bundle by declaring them as external, and map their module IDs to properties on a global variable (e.g. window.__vendor) using output.globals. The name of the global variable is set by the name plugin option.

On the other hand, the producer simply sets output.name to the same name as the global variable, and replaces the entrypoint with a script re-exporting the modules so the main bundle can access them:

export {default as React} from 'react';
export {default as ReactDom} from 'react-dom';

Current Tags

  • 1.0.0                                ...           latest (2 years ago)

1 Versions

  • 1.0.0                                ...           2 years ago
Maintainers (1)
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 2
Dependencies (4)
Dev Dependencies (0)
Dependents (0)

Copyright 2014 - 2016 © taobao.org |