-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Description
Version: webpack@5.44.0
While playing around with https://webpack.js.org/guides/asset-modules/ in webpack@5, i wondered why the production build doesn't inline the resources and instead keeps them in module form.
I'm talking about this kind of rule:
{
test: /\.jpg$/,
type: 'asset/resource',
generator: {
emit: false,
filename: 'foobar123456',
},
},This creates a module for every file that just returns a string. Adding sideEffects:false seems to yield the same.
What we do right now is having a loader that returns the filename as:
export default /*#__PURE__*/ "foobar123456"
which lets webpack dissolve the module in production build and inline the string. I guess those type: 'asset/resource' could be marked as pure as well?
See reproduction
https://github.com/sod/webpack-resource-pure
config: https://github.com/sod/webpack-resource-pure/blob/main/webpack.config.js
input: https://github.com/sod/webpack-resource-pure/blob/main/src/index.js
output: https://github.com/sod/webpack-resource-pure/blob/main/dist/main.js (see bar.jpg was inlined, foo.jpg was not)
custom pure loader: https://github.com/sod/webpack-resource-pure/blob/main/image-string-loader.js
We don't need any change here as the loader works just fine. Was just wondering.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status