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.
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
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:

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.
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.