Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support generating a UMD bundle #766

Closed
ghost opened this issue Feb 8, 2018 · 10 comments
Closed

Support generating a UMD bundle #766

ghost opened this issue Feb 8, 2018 · 10 comments

Comments

@ghost
Copy link

ghost commented Feb 8, 2018

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.

@danawoodman
Copy link

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

@devongovett devongovett changed the title Ability to create named libraries Support generating a UMD bundle Feb 20, 2018
@devongovett
Copy link
Member

Related: #453

@willin
Copy link

willin commented Mar 12, 2018

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

@devongovett
Copy link
Member

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

@willin
Copy link

willin commented May 2, 2018

UMD...

@random-yang
Copy link

random-yang commented Dec 25, 2019

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 !

@mischnic
Copy link
Member

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

@niieani
Copy link

niieani commented Oct 13, 2021

@devongovett is UMD still supported in Parcel 2? I see no mention of it in the docs - should we re-open this issue? Thanks! 🙇

@danmarshall
Copy link
Contributor

@niieani - I'm not sure why this is not in V2, but here is my workaround:

window['MyGlobalName'] = myGlobalVar;

@zhaoyao91
Copy link

zhaoyao91 commented Oct 14, 2021

@niieani - I'm not sure why this is not in V2, but here is my workaround:

window['MyGlobalName'] = myGlobalVar;

Need umd/iife format in v2
it is expected to bundle all dependencies into the final bundle expect the native node modules.
I guess your workaround won't handle the dependencies bundling problem.

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

No branches or pull requests

8 participants