-
Notifications
You must be signed in to change notification settings - Fork 22
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
#113: Upgrade to Webpack 5 #421
Conversation
48dc67d
to
bb5871e
Compare
Example: WARNING in DefinePlugin Conflicting values for 'process.env.NODE_ENV'
Solved a warning, caused errors
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.
Hallelujah CI passes
process: true, | ||
Buffer: true, | ||
console: true, | ||
fs: "empty", |
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.
Webpack 5 no longer includes polyfills by default, so I ended up using https://github.com/Richienb/node-polyfill-webpack-plugin instead of installing 7 dependencies separately and configuring them here.
filename: "css/[name].css", | ||
chunkFilename: "css/[id].css", | ||
ignoreOrder: false, // Enable to remove warnings about conflicting order | ||
}), |
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.
This should already be inherited from webpack.base.js
}, | ||
extensions: [".ts", ".tsx", ".jsx", ".js"], | ||
fallback: { | ||
chokidar: false, |
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.
Some packages like handlebar and nunchucks do dependency checks via try {require()}
, which cause webpack to bundle the dependency.
It seems that many of these dependencies are not required and should not be part of the browser anyway. As part of #411 I can look into the specific modules and find web-only entry points for each, if they exist.
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.
Could you clarify what you mean by "and find web-only entry points for each" means? Not familiar with it
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.
The filename and option suggest that this file, which is required and bundled into PixieBrix, is actually meant to be run on Node. Some packages offer browser-only bundles (browser
field in package.json
) without all of this Node-specific cruft — I'll look for them.
Sub-dependencies like this one were resolvable at some point because some other package downloaded them, but I suppose that these changes resurfaced this (unnecessary) dependency mismatch and caused the build to fail.
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.
I think I understand now -- e.g., you'd find an entry point to nunjucks that doesn't reference the node-loaders module. That would prevent webpack from looking for chokidar in the first place, so we wouldn't have to explicitly tell webpack not to resolve it. Is my understanding correct?
For the sake of expediency, I'd also be ok marking things as false
to get the build to pass after we do a quick check like you did to make sure they're not going to cause a problem
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.
That’s correct. The current code already builds and should match more or less what existed before, so dependency-wise it shouldn’t need further changes in this PR (I’d rather merge the upgrade first, and only then do optimizations).
I’ll run the extension today and see what’s missing.
The extension runs, but please do a quick run through to ensure it's not broken in some obvious ways. |
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.
Getting some errors when running the extension on pages. Looks like one of these is related to the path changing for the css files?:
Denying load of chrome-extension://mpjjildhmpddojocokjkgmlkkkfjnepo/icons.css. Resources must be listed in the web_accessible_resources manifest key in order to be loaded by pages outside the extension.
In general, a good way to test big changes is by just running through the https://docs.pixiebrix.com/quick-start-guide quickly
], | ||
module: { | ||
rules: [ | ||
// https://github.com/webpack/webpack/issues/3017#issuecomment-285954512 | ||
// prevent lodash from overriding window._ | ||
{ | ||
exclude: /(notifyjs-browser|vendors\/notify)/, | ||
parser: { amd: false }, |
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.
@fregante What was the reason for removing this? I had originally added this since having lodash overwrite window._ breaks sites running older versions of lodash
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.
Sorry I blindly removed this line since it was deprecated:
Module not found: ValidationError: Invalid parser object. Json Modules Plugin has been initialized using a parser object that does not match the API schema.
- parser has an unknown property 'amd'. These properties are valid:
object { parse? }
I pushed a tentative solution for this. It compiles but I haven't run it.
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.
Thanks, I can help show you how to test it. I think you just find a page where the PixieBrix contentScript is loaded and see if it set window._
or not.
To do that, you could just click the PixieBrix extension icon in the Chrome toolbar on any page to trigger the browser action, which will inject the contentScript and the side bar
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.
- I clicked the button
- The sidebar appeared on the page
window._
is undefined in thetop
frame in the consolewindow._
is undefined in content script extension in the console
I also verified that without amd: false
, window._
is a function in both context; This means amd: false
fixes this Lodash issue. 🎉
However I think that this is breaking notify.js
, so I will probably just drop the UMD from its bundle and adjust it to work correctly. The file is dated 2015 anyway.
}, | ||
extensions: [".ts", ".tsx", ".jsx", ".js"], | ||
fallback: { | ||
chokidar: false, |
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.
Could you clarify what you mean by "and find web-only entry points for each" means? Not familiar with it
Something that confused me are the CSS files actually. It appears that most CSS files appear both at the entry point and inside the CSS folder. Also there’s a CopyPlugin configuration in the prod files that copied everything from src, unchanged. What was the reason for that? |
From
The first one ends up copying over the The second one copies over |
Everything seems to be fine now. I don't see any errors other than #428, which also appears on |
Testing the PR now
Will see if it's actually an issue. On package install, I get a peer dependency warning: npm WARN webpack-extension-reloader@1.1.4 requires a peer of webpack@^4 but none is installed. You must install peer dependencies yourself. |
Yeah that dependency was meant to be removed as discussed in #113 (comment), but I left it in so I can properly document what will replace it. |
Closes #113
This PR tries to be as minimal as possible. Build improvements will come in a future PR.
This appears to build and I'm pushing it here to double-check on the PR. I still need to test it and possibly refine it further. There are a lot of moving parts so it's taking a long while.Related issues include:
However I did not encounter the HMR issue described in #113. Was that at build time or runtime?