Parcel: Support generating a UMD bundle

Created on 8 Feb 2018  Â·  7Comments  Â·  Source: parcel-bundler/parcel

Choose one: feature request?

Right now, parcel is used for compiling code to be used for a frontend server. There's no way to create a named library that you can use drop in a <script src='...'> tag and call via myLibrary.Foo(). Both rollup and webpack allow you to specify a config similar to

output: {
    file: 'dist/styled-components.js',
    format: 'umd',
    name: 'styled',
    exports: 'named',
}

It would be awesome if parcel supported something similar and wasn't strictly for server/html code.

Help Wanted Feature

Most helpful comment

Fixed by #453. Modules are now exposed to CommonJS and AMD automatically, and if you specify a --global <name> flag, as a global variable.

All 7 comments

I too would be able to use Parcel more if this was supported. It is equivalent to WebPack's output.library option.

It is also equivalent to Rollup's output.format option.

https://rollupjs.org/guide/en#command-line-flags

  • -f, --output.format [es] Type of output (amd, cjs, es, iife, umd)
  • -n, --name Name for UMD export

Fixed by #453. Modules are now exposed to CommonJS and AMD automatically, and if you specify a --global <name> flag, as a global variable.

UMD...

Fixed by #453. Modules are now exposed to CommonJS and AMD automatically, and if you specify a --global <name> flag, as a global variable.

This work for me, but there sames no way to expose myvariable on the globle window.

// lib.js

export default { ... }

then run parcel build lib.js --global mylib

<!-- index.htm -->
<script src'./lib.js'></script>
<script>
console.log(mylib)
</script>

the out put is:
image
Now I wanna use is have to code mylib.default, which is really wired.
How can I make mylib is mylib.default‘'s value.

Thanks !

You cannot use ESM exports for that. module.exports = ... would make it available as mylib.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

devongovett picture devongovett  Â·  3Comments

dotdash picture dotdash  Â·  3Comments

jzimmek picture jzimmek  Â·  3Comments

davidnagli picture davidnagli  Â·  3Comments

philipodev picture philipodev  Â·  3Comments