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

How to use protocol inside webpack? #377

Closed
april opened this issue Apr 26, 2019 · 5 comments
Closed

How to use protocol inside webpack? #377

april opened this issue Apr 26, 2019 · 5 comments

Comments

@april
Copy link

april commented Apr 26, 2019

I'm trying to use protocol inside of webpack (with HtmlWebpackPlugin), and I've been banging my head against it for hours without much success.

All of the included JavaScript files set things directly on window, e.g. window.Mzp.Navigation = Navigation, instead of using export. Am I missing something terribly obvious?

Thanks!

@april april changed the title Use protocol inside webpack How to use protocol inside webpack? Apr 26, 2019
@alexgibson
Copy link
Member

The copy-webpack-plugin may be help here to copy the protocol source to your build directory.

I used that here as an example if that may be useful https://github.com/mozmeao/performance-dashboard/blob/master/webpack.config.js

@april
Copy link
Author

april commented Apr 29, 2019

Hmm, that's pretty non-ideal. It would be much better if I could simply import @mozilla-protocol/core and have access to the entire library, while letting tree-shaking minimize it. The CSS already works great this way, just not the JavaScript.

It's been a while since I've used a library that only worked with access to window, for this very reason.

@alexgibson
Copy link
Member

alexgibson commented Apr 29, 2019

Yeah, we only have a few pieces of JS currently to be honest, so i’m not sure how much you would really benefit from tree shaking here. We do have transpiling on our roadmap, but it’s not currently a top priority.

Either way, you can still use ES5/a global with web-pack for the time being.

@alexgibson
Copy link
Member

@craigcook now that bedrock is also using webpack, I think it might be a good idea to enable our JS components to be imported. We could still keep the global variable I think for backward compatibility.

@craigcook
Copy link
Member

This can be bundled in with #255

@craigcook craigcook closed this as not planned Won't fix, can't repro, duplicate, stale Feb 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants