Given an es6 input file, output its dependencies in a separate bundle
Last updated 2 months ago by mnutt .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install rollup-split-index 
SYNC missed versions from official npm registry.


Splits dependency tree into the entrypoint file and all the rest.

The purpose of this module is to use rollup to bundle all dependencies into a single file while leaving the index.js file human-readable (and human-editable). It does this with two plugins; dependenciesOnly can be used while generating dist/vendor.js and importExportToGlobal can be used while generating dist/index.js.


$ yarn add rollup-split-index
# or:
$ npm install --save rollup-split-index


Your rollup.config.js file can look like this:

const config = require("./package.json");
const rollup = require("rollup");

const resolve = require("rollup-plugin-node-resolve");
const commonjs = require("rollup-plugin-commonjs");

const {
} = require("rollup-split-index");

const inputFile = config.main; // likely index.js

module.exports = [
    input: inputFile,
    plugins: [resolve(), commonjs(), dependenciesOnly()],
    output: {
      name: importExportToGlobal.referenceName,
      file: "dist/vendor.js",
      format: "iife"
    input: inputFile,
    plugins: [resolve(), commonjs(), importExportToGlobal()],
    output: {
      file: "dist/index.js",
      format: "es"

You can then run rollup as usual with:

$ node_modules/.bin/rollup -c rollup.config.js

This will load index.js, trace its dependency tree including node_modules, and bundle all dependencies into dist/vendor.js. The vendor.js file will export a __rollup_vendor object referencing all of the imports.

In addition, this will transform index.js by rewriting es6 imports and exports to global declarations. For example:

import jQuery from 'jquery';
export default MyApp


const jQuery = __rollup_vendor['jquery']
window.MyApp = MyApp;

You should then be able to load both files in script tags and then reference the default exported variable:

<script src="./dist/vendor.js"></script>
<script src="./dist/index.js"></script>



Current Tags

  • 1.1.0                                ...           latest (2 months ago)

3 Versions

  • 1.1.0                                ...           2 months ago
  • 1.0.1                                ...           a year ago
  • 1.0.0                                ...           a year ago
Maintainers (1)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (5)
Dev Dependencies (2)

Copyright 2014 - 2016 © |