Skip to content

Instantly share code, notes, and snippets.

@Raynos
Created October 9, 2020 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Raynos/54a9ee571048980f810ad5e315500520 to your computer and use it in GitHub Desktop.
Save Raynos/54a9ee571048980f810ad5e315500520 to your computer and use it in GitHub Desktop.

I attempted to use parcel to bundle a commonJS project.

Example code

For example

const assert = require('assert')

const MyWebComponent = require('./my-web-component')

async function main () {
  const comp = new MyWebComponent()
  assert(comp.tagName, 'is component')

  document.body.appendChild(comp)
}

main()

What I tried

I tried compiling this with parcel

parcel build src/index.js -d src -o bundle.js

I was suprised that when running it complained about regenerator ( parcel-bundler/parcel#2128 ).

I was frustrated that parcel used babel to "compile" my async function when my browser support async/await.

I could not find a parcel --no-babel flag.

Trying node / commonJS

I did however find a parcel --target node --bundle-node-modules option.

This worked great until i got a runtime exception related to cannot find module assert.

My browser environment needs https://github.com/browserify/commonjs-assert to be bundled. I could not find any CLI flags that said polyfill builtin node modules.

I did find this documentation https://v2.parceljs.org/features/node-emulation/ but there was no CLI flag to turn node emulation on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment