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

UMD build undefined when no default export #411

Closed
bebbi opened this issue Dec 8, 2017 · 2 comments
Closed

UMD build undefined when no default export #411

bebbi opened this issue Dec 8, 2017 · 2 comments

Comments

@bebbi
Copy link

bebbi commented Dec 8, 2017

This issue is a:

  • Bug report

I have a vanilla JS web component that defines named exports in src/index.js like such:

export {  a, b, c }

This leads to the umd global variable being undefined.

If changing above to a default export

export default {  a, b, c }

things work for umd, and the umd variable is an object as expected { a, b, c }

I've read that nwb recently dropped the need to address default exports via .default.
Perhaps that change has to be skipped if named exports are present?

Is the version of nwb you're using installed globally or locally?
global

Which versions of Node.js, npm and nwb are you using (if using it globally)?
node v8.9.1, yarn@1.3.2, nwb@0.20.0

@insin
Copy link
Owner

insin commented Dec 8, 2017

I've created a Webpack feature request for this, as it would be nice for everyone if output.libraryExport automatically exported the default export when a library's entry module is using ES2015 modules instead of having to configure it:

webpack/webpack#6097

Faiing that, alternative courses of action are:

  • Add support for some new configuration under the umd config object in nwb.config.js to tell nwb how you're exporting your library (low effort)
    • e.g. umd.exports, which can be default or named and is used to set Webpack's output.libraryExport appropriately
    • e.g. umd.entry, which allows you to provide a separate entry module for UMD builds which must export default
    • Add comments to src/index.js in the react-component and web-module project templates to document that you must export default or the UMD build won't work by default, with directions to the appropriate configuration options if you'd rather use named exports because default.
  • Switch nwb over to Rollup for UMD builds (high effort, need to investigate Rollup properly and its plugin ecosystem for parity with features available in current Webpack build, such as aliases and defining replacements of certain expressions)

It's not ideal, but in the meantime you should be able to use webpack.extra or webpack.config() in nwb.config.js to override output.libraryExport when performing a UMD build.

@insin insin added the bug label Dec 8, 2017
@jimniels
Copy link

jimniels commented Jan 31, 2018

Thanks for the comments on this. I found myself in a similar situation and used the webpack.config() option to solve my problem.

However, FWIW, from my perspective, a umd.entry file would be ideal, as it would provide me a separate place to define my UMD build.

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

3 participants