Asset modules
Rspack's built-in asset modules let you import images, fonts, and other files without installing a loader.
Import an image
To display src/logo.png on a page, add a rule that handles PNG imports as asset/resource:
Import the image from JavaScript and use its URL as the image source:
Rspack emits a copy of the image in the output directory. The default import, logoUrl, is the URL the browser uses to load that file.
URL references
In a stylesheet processed by Rspack's built-in CSS support, use url() with a path relative to the stylesheet:
In JavaScript, you can also use new URL() with a path relative to the current module. Rspack handles local files referenced this way as asset/resource by default, so this example works without a PNG rule:
Asset types
Inline small assets
With type: 'asset', files up to and including 8096 bytes are inlined by default. To lower the limit to 4 KiB for PNG imports, change the PNG rule:
Both imports below return strings you can use as an image source. Only the larger image is emitted as a file:
To set the limit for all asset rules, use module.parser.asset.dataUrlCondition. Inlined files use Base64 encoding by default. To change the encoding, see generator.dataUrl.encoding.
Import text or bytes
To read the contents of a file for a single import, use the text or bytes import attribute. Rspack provides default rules for both:
If your project uses ?raw to import source text, configure oneOf on the SVG rule. In the first branch, match ?raw imports with resourceQuery: /raw/ and set type: 'asset/source'. In the second branch, set type: 'asset/resource' so ordinary imports return the file URL.
Loader migration
If your project uses one of these loaders, replace it in the matching rule:
To compress PNG images before emitting them, configure ImageMinimizerPlugin.loader from image-minimizer-webpack-plugin and its compression options in the PNG rule's use array. asset/resource emits the compressed image.

