feat: consider asset module as side-effect-free#20352
Conversation
🦋 Changeset detectedLatest commit: 288c500 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 |
|
This PR is packaged and the instant preview is available (5ecc58d). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@5ecc58d
yarn add -D webpack@https://pkg.pr.new/webpack@5ecc58d
pnpm add -D webpack@https://pkg.pr.new/webpack@5ecc58d |
2bed3ee to
c56b046
Compare
CodSpeed Performance ReportMerging this PR will not alter performanceComparing Summary
Footnotes |
|
Looks like we need to fix tests, but code looks good |
|
We should consider a better approach for setting |
|
@hai-x Yeah, we have the same problem with renaming modules, alternative solution - make builtMeta and buildInfo as getters, but will be glad to have a hook to setup it |
This reverts commit c56b046.
|
I use |
| }) | ||
| ); | ||
| } | ||
| }); |
There was a problem hiding this comment.
What about to rewrite test to see that unused module was removed, we have __webpack_modules__ to check them in chunk
3302b9d to
54d2801
Compare
4d2a9c1 to
c3b05b6
Compare
|
Thanks for review. It such one good idea to use |
Webpack v5.105.0 treats assets as side-effect free, see: webpack/webpack#20352
|
Just a heads up: this broke our build. We marked fonts to include in the build with side-effect only imports from our code import "~/assets/my-font.woff"and as expected, this caused the font not to be copied anymore. I think there should be extra documentation in https://webpack.js.org/guides/asset-modules mentionning this can be forced using {
test: /\.(woff|woff2)$/,
generator: {
filename: 'fonts/[name][ext]',
},
type: 'asset/resource',
sideEffects: true,
}, |
|
@GerkinDev We should fix it, it is a bug /cc @hai-x Let's do mark them as side effect free for side-effect only imports |
Webpack v5.105.0 treats assets as side-effect free, see: webpack/webpack#20352
|
Just a heads up: this broke our build. We marked fonts to include in the build with side-effect only imports from our code import "~/assets/my-font.woff"and as expected, this caused the font not to be copied anymore. I think there should be extra documentation in https://webpack.js.org/guides/asset-modules mentionning this can be forced using {
test: /\.(woff|woff2)$/,
generator: {
filename: 'fonts/[name][ext]',
},
type: 'asset/resource',
sideEffects: true,
}, |
|
@GerkinDev We should fix it, it is a bug /cc @hai-x Let's do mark them as side effect free for side-effect only imports |
Summary
What kind of change does this PR introduce?
Fixes part of #20209.
Did you add tests for your changes?
Yes
Does this PR introduce a breaking change?
Theoretically not
If relevant, what needs to be documented once your changes are merged or what have you already documented?
No