-
Notifications
You must be signed in to change notification settings - Fork 149
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
Upgrade to webpack v5 #614
Conversation
9689056
to
2d24957
Compare
2d24957
to
97a49e9
Compare
267ed78
to
b335388
Compare
97a49e9
to
7dfcb5a
Compare
64a41e7
to
5418dd5
Compare
b335388
to
06307ca
Compare
5418dd5
to
a43a6f4
Compare
a43a6f4
to
97d1576
Compare
f4516b4
to
a45c36a
Compare
97d1576
to
cac257c
Compare
a45c36a
to
a1accc3
Compare
90900ca
to
f0f41d3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Project built OK and accessible-autocomplete.min.js loaded OK in a browser.
Tried to load the library (using Node, for quickness) both with require
and import
which noticed that dist/accessible-autocomplete.min.js
was adding to self
rather than window
as it does now, so we should probably go like-for-like (or even move to this
as GOV.UK Frontend does?).
webpack.config.mjs
Outdated
|
||
output: { | ||
...config.output, | ||
globalObject: 'window' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue I think this one needs to go in the shared config's output
, so that the wrapped version of the library also gets added to window
, as it is with Webpack 4. With Webpack 5, looks like it gets added to self
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interestingly, looks like on GOV.UK Frontend, we add to this
rather than either of window
or self
. this
sounds more portable, but:
- isn't like for like with the current output of Webpack
- I'm not quite sure if there'd be unforeseen side effects
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@romaricpascal Shall we pair on this?
You'll notice the difference when importing into the Review app
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
During testing, sounds like a conflict happened if setting the accessible-autocomplete.min.js
to 'window', so let's keep it on self
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's when running without a bundler (e.g. dependencies via unpkg <script>
)
It means we can use window.React.createElement()
in user code but still ensure React inside our bundled library code still resolves and extends the window.React
version using webpack globalObject
I'll add a comment to explain:
// Support extending `window.React` when not bundled
// e.g. with all dependencies included via unpkg.com
globalObject: 'window'
f0f41d3
to
e9a4bdd
Compare
e9a4bdd
to
ff3f5a6
Compare
Let's just check that things still work serverside for React, as it was something specifically handled by this PR. |
@romaricpascal Yep, all working as discussed on Slack There's an extra commit 1746717 to fix server-side imports without breaking I've clarified why we use import Autocomplete from 'accessible-autocomplete/react.js'
import React from 'react'
import ReactDOMServer from 'react-dom/server.js'
console.log(
ReactDOMServer.renderToString(
React.createElement(Autocomplete.default, {}, null)
)
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks all good to go. Had a quick re-test through GOV.UK Frontend review app and it all worked fine.
Upgrade to webpack v5
With manual testing to confirm these three UMD entry points still work:
Package audit
See results from
npm audit
below