babel/generator-babel-boilerplate

Export "ordinary" browser library, without `default` property

Closed this issue ยท 10 comments

Is there a way to build my project so I can use it like other ordinary libraries (like jQuery, moment.js etc.).

When I build my project and I load the file in the dist folder in an html file via a <script src="myLib.js"> element I get an object containing a default property. E. g. myLib.default.initMyLib().

What I want instead is an object like this: myLib.initMyLib(). Is this possible using this boilerplate? If so, how?

It used to work that way, and should still. I just haven't loaded a library like that in a long time, so a regression may have been introduced. I'll look into it and try to get this fixed up ๐Ÿ™‚

@alinnert , I dug into it. This is caused by Babel v6 + Webpack v1's current behavior.

Webpack v2 should handle it as you'd expect, but it's in beta so I don't plan to update the boilerplate to use it atm. You're free to swap in Webpack v2 in your own project! You could use this boilerplate as inspiration for how to get that set up.

A PR to update the behavior in Webpack v1 is open over here:

webpack/core#23

Related issue: webpack/webpack#2047

Not too much I can do in the meantime!

//cc @marcandre this one's going to matter to you, if I had to guess ๐Ÿ˜›

Cross-referencing #368 which is relevant

I can fix this with this plugin. I'll add this very soon.

@alinnert the fix for this is straightforward to implement in a per-project basis by installing this plugin and adding it to the generated .babelrc file. For this reason, I'm going to hold off on adding it to the boilerplate for the time being.

I'm going to reopen this to remind myself to add a section to either the FAQ or the trouble shooting section for this.

The plugin works great ! Thanks. Indeed, adding to the FAQ / README, would be nice.

@gabrielstuff I'm glad that worked out for you! Would you have time to add it to the README? :) I'd happily merge it in!

Tomorrow morning, with pleasure. Struggling a bit with my externals and other webpack funs. Thanks

Awesome. Thanks so much @gabrielstuff !