I'm building a Javascript library using ES6. For bundling, I moved away from Webpack and started to use Rollup. However, I'm having issues transpiling. It looks like async/await is not handled properly. Does any one have a working rollup.config.js you would like to share?
Any tips and suggestions are welcome. Thanks!
I figured it out. In case any one is interested, here is my
rollup.config.js:import resolve from "rollup-plugin-node-resolve"; import commonjs from "rollup-plugin-commonjs"; import babel from "rollup-plugin-babel"; import { terser } from "rollup-plugin-terser"; import pkg from "./package.json"; babel({ babelrc: false, exclude: "node_modules/**", runtimeHelpers: true, presets: [ [ "@babel/preset-env", { modules: false, useBuiltIns: "usage" } ] ], plugins: [ "@babel/plugin-proposal-class-properties", "@babel/plugin-transform-runtime" ] }); export default [ // CommonJS (for Node) { input: "src/index.js", output: [{ file: pkg.main, format: "cjs", exports: "default" }], plugins: [ babelPlugin, resolve(), commonjs(), //terser(), ] }, // ES module (for bundlers) { input: "src/index.js", output: [{ file: pkg.module, format: "es", exports: "default" }], plugins: [ babelPlugin, //terser() ] } ];My goal was to create a
esm,cjs, andumd(not shown on the config) version of the library. The source uses features likeasync/awaitand class properties. After minimal initial testing, things look good. I think the issue originally was not thatasync/awaitwasn't handled properly, but that my version of Node wasn't supportingnew Url(). After upgrading to v10, it worked fine. The tricky part here is that the source of the library needs to be isomorphic. I usedisomorphic-unfetchand the newest version of Node to solve the issues I was having.