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

Fix various Karma + webpack warnings and minor issues #641

Merged
merged 6 commits into from
Jan 19, 2024

Conversation

colinrotherham
Copy link
Contributor

@colinrotherham colinrotherham commented Jan 19, 2024

This PR includes a few follow-up fixes to Karma + webpack

Fix Karma webpack output to prevent overwriting dist/

Previously npm run karma used webpack to overwrite dist/ but using karma-webpack defaults instead. This has now been fixed so that Karma output is written to os.tmpdir() as the author intended

Fix Karma webpack karma-sourcemap-loader warnings

Karma webpack devtool option now outputs inline source maps to fix warnings about missing source maps

Ensure webpack uses new serve CLI command

We can now use the webpack CLI rather than the webpack-dev-server package binary:

npx webpack
npx webpack serve

Ensure webpack always exits on build errors

The webpack NoEmitOnErrorsPlugin plugin is now enabled by default but we turn it off in development mode to help diagnose problems in the browser rather than exit

Warnings since webpack v5 update

Additionally, new warnings have been fixed following the webpack v5 update:

Fix Karma webpack performance warnings

The Karma webpack stats: 'errors-only' option has been updated for webpack v5 to ignore performance warning recommendations since these are only useful for production builds

Fix Karma webpack DefinePlugin warning for NODE_ENV

The Karma webpack build runs with NODE_ENV=test but this logs a warning in webpack v5 because “test” does not match webpack config.mode allowed values "none" | "development" | "production"

Uses the new `emitOnErrors: true` and CLI specific `bail: true` unless in development
Karma runs with `NODE_ENV=test` but logs a warning because “test” does not match webpack `config.mode` allowed values `"none" | "development" | "production"`
We should also output inline source maps for `NODE_ENV=test` so these can be picked up by Karma
These were previously suppressed but webpack v5 needs a separate `performance` option alongside the `errors-only` preset
@colinrotherham
Copy link
Contributor Author

I did investigate webpack clean: true but it deletes the custom React and Preact bundles

It appears that webpack is unaware we override the output path to dist dist/lib so they get "cleaned"

Copy link
Member

@romaricpascal romaricpascal left a comment

Choose a reason for hiding this comment

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

That's a good couple of tidy ups 🙌🏻 Tried dev, test and build commands locally and it all looked fine. ⛵

@colinrotherham colinrotherham merged commit 455445a into main Jan 19, 2024
3 checks passed
@colinrotherham colinrotherham deleted the karma-webpack-fixes branch January 19, 2024 16:00
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

Successfully merging this pull request may close these issues.

2 participants