feat(create-webpack-app): use webpack's native CSS and HTML support in init templates - #4833
Open
bjohansebas wants to merge 1 commit into
Open
feat(create-webpack-app): use webpack's native CSS and HTML support in init templates#4833bjohansebas wants to merge 1 commit into
bjohansebas wants to merge 1 commit into
Conversation
…n init templates Replace css-loader, style-loader, vue-style-loader and mini-css-extract-plugin with `experiments.css`, and html-webpack-plugin and html-loader with `experiments.html`, where `index.html` becomes the entry point. Both experiments default to "auto" since webpack 5.109, so the templates only declare them when the auto detection would turn them off: a PostCSS rule for `.css` files, and the Vue template, where VueLoaderPlugin clones every non-vue rule with a catch-all `resource: () => true` matcher before webpack resolves the defaults, which makes the auto detection see a loader for `.css` and `.html`. The Vue template also needs `experimentalInlineMatchResource` in vue-loader, required with `experiments.css`. The "Do you want to extract CSS into separate files?" prompt is gone, native CSS always emits separate files, and the `htmlWebpackPlugin` answer is now `html`.
🦋 Changeset detectedLatest commit: 3af8da4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
|
This PR is packaged and the instant preview is available (3af8da4). Install it locally:
npm i -D create-webpack-app@https://pkg.pr.new/create-webpack-app@3af8da4
yarn add -D create-webpack-app@https://pkg.pr.new/create-webpack-app@3af8da4
pnpm add -D create-webpack-app@https://pkg.pr.new/create-webpack-app@3af8da4 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4833 +/- ##
==========================================
+ Coverage 93.32% 93.35% +0.03%
==========================================
Files 14 14
Lines 5466 5401 -65
Branches 793 790 -3
==========================================
- Hits 5101 5042 -59
+ Misses 363 357 -6
Partials 2 2
Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
inittemplates still scaffolded CSS and HTML through loaders and plugins that webpack now handles natively. This PR moves the four templates (default,react,vue,svelte) to webpack's built-in support:experiments.cssreplacescss-loader,style-loader,vue-style-loaderandmini-css-extract-plugin. Sass/Less/Stylus and PostCSS are wired throughtype: "css/auto"rules.index.htmlbecomes the entry point, handled byexperiments.html, replacinghtml-webpack-pluginandhtml-loader.Both experiments default to
"auto"since webpack 5.109, so the generated configs only declare them where the auto detection would turn them off:.cssfiles registers a loader for CSS, which disables the auto default (without an explicitexperiments.css: truethe build fails withNo parser registered for css/auto);VueLoaderPluginclones every non-vue rule with a catch-allresource: () => truematcher, and plugins are applied before webpack resolves the defaults, so the auto detection sees a loader for both.cssand.html. The Vue template also setsexperimentalInlineMatchResourceinvue-loader, which that loader requires whenexperiments.cssis enabled.The "Do you want to extract CSS into separate files?" prompt is gone, since native CSS always emits separate files, and the
htmlWebpackPluginanswer is now namedhtml.What kind of change does this PR introduce?
feat
Did you add tests for your changes?
The existing
test/create-webpack-app/initsuite covers this; its snapshots are updated for the new configs and dependency lists. Beyond the suite, I generated a project from each of the four templates and ran a production build: the emittedindex.htmlgets the<link>/<script>tags injected and CSS is emitted as a separate file, and in the Vue app scoped SFC styles come out correctly (.sfc-test[data-v-6493cde5]).Does this PR introduce a breaking change?
Not for existing projects, they are unaffected. Newly generated projects change: they no longer install the CSS/HTML loaders and plugins,
index.htmlis the entry point, and the CSS extraction prompt is gone. ThehtmlWebpackPluginanswer key is renamed tohtml, which affects anyone driving the generator programmatically. Released as a minor forcreate-webpack-app(changeset included).If relevant, what needs to be documented once your changes are merged or what have you already documented?
Nothing beyond the changeset in this PR.
Use of AI
Yes. I used Claude Code (Opus) to carry out the migration across the templates and generators, under my direction and step by step. Every claim in the description was verified by actually generating and building the projects rather than assumed, and I reviewed the final diff.