Combine multiple es6 classes into single library using rollup js

时间:2018-06-04 16:40:24

标签: rollup rollupjs umd

How can I import a.js and b.js and export as combined bundle.js in UMD format using rollupjs?

Here is the example:

//a.js
export default class A {
...
}

//b.js
export default class B {
...
}

My current rollup.config.js is:

export default [
  {
    input: ["path/a.js", "path/b.js"],
    output: {
      file: "path/bundle.js",
      format: "umd",
      name: "Bundle"
    },
    plugins: [
      // list of plugins
    ]
  }
}

However, this is not working as intended.

Anything wrong with this config?

Thanks for your help.

1 个答案:

答案 0 :(得分:0)

您需要一个文件来将它们绑在一起。因此,与a.jsb.js一起,有一个main.js如下所示:

import A from './a';
import B from './b';

export default {
  A,
  B,
};

然后用rollup.config.js更新您的input: path/main.js