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

chores(javascript): cleanup NPM and Webpack #2934

Merged
merged 4 commits into from
Jul 21, 2023

Conversation

cweider
Copy link
Collaborator

@cweider cweider commented Jul 21, 2023

Fixes issues:

  • Dependency resolution error c/o webpack-cli had prevented npm install
  • Current packaged Javascript hasn't matched compiled Webpack output since upgrade to version 5 (8256590)
  • npm audit reported several vulnerable packages

cweider added 4 commits July 21, 2023 12:13
When running `npm install`, a dependency resolution
error for `webpack` comes up. `[email protected]`
requires `[email protected]`, but the project requires
`webpack@^5.76.0`.

Resolve by uncritically updating the version of
`webpack-cli` to match that of `webpack-dev-server`,
`^4.10.0`.

Make adjustments to `webpack.config.js` to work with
this newer version (see `devServer.writeToDisk`).
Its use was removed in 1f60671. Prune it and its dependencies.
Webpack was upgraded to version 5 in 8256590, but has not
been used to generate Javascript. Webpack 5 includes quite
a few changes and, unfortunately, generates different
compiled output.

Notably, it strips and extracts license-like comments into
a `LICENSE.txt` file. Handle this by using a `TerserPlugin`
with a custom configuration (which is, evidently, the
recommended approach). Another difference was was source-map
generation. Seeing that existing files are essentially empty,
remove source-maps for the time being. Sadly, nothing can be
done about the different order of concatenation.

Webpack 5 Release Notes:
https://webpack.js.org/blog/2020-10-10-webpack-5-release/
This updates the transitive dependencies, `semver`, `word-wrap`,
and `caniuse-lite`. None cause a change in the generated
Javascript.

This resolves the "3 moderate severity vulnerabilities" that npm
would complain about and also the complaint about `Browserslist`
from Webpack.
@cweider cweider force-pushed the javascript-chores branch from 040e290 to a00a4ce Compare July 21, 2023 19:30
@@ -1 +0,0 @@
{"version":3,"file":"vendor.js","sources":["webpack:///vendor.js"],"mappings":"AAAA;;;;;AA8ZA;AAyoCA;;;;AA8sKA;;;;;AAsvaA;;;;;;;AAy/FA;;;;;;;;AAkiRA;;;;;;;;AAmCA;;;;;;;;AAoTA;;;;;;;;AA28BA;;;;;;;;AA0YA;;;;;;;;AAg7DA;;;;;;;;AAkCA","sourceRoot":""}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not sure why sources is only ["webpack:///vendor.js"] (or how to generate this output). The good news is that it means this source map is essentially meaningless – and harmless to remove.

terserOptions: {
compress: true,
},
})],
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t love this non-default plugin, but this is evidently how you preserve comments. Moving to LICENSE.txt (the default imposed by Webpack 5) is something to consider, but, on balance, the added complication of this plugin is worth removing urgency of reconsidering our source attribution approach!

@@ -1 +0,0 @@
{"version":3,"file":"main.js","sources":["webpack:///main.js"],"mappings":"AAAA","sourceRoot":""}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cf. vendor.js.map

@mlissner mlissner merged commit 76d085c into freelawproject:main Jul 21, 2023
@mlissner
Copy link
Member

LGTM, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants