To embed the contents of an SVG file into your site using NextJS with the new Rust-based compiler (Turbopack), perform the following steps:
- Install
@svg/webpack:
$ npm install --save-dev @svgr/webpack- Add to your webpack config in
next.config.jswith the following options. This will remove the width and height from the SVG but keep the viewBox for correct scaling.
module.exports = {
turbopack: {
rules: {
'*.svg': {
loaders: [
{
loader: '@svgr/webpack',
options: {
svgoConfig: {
multipass: true,
plugins: ['removeDimensions'],
},
},
},
],
as: '*.js',
},
},
},
}- Import SVG into component
import Logo from 'public/images/logo.svg';- Use the Component
<Logo className="h-8 w-auto sm:h-10" alt="Site Title" />
Hey, it work fine for we but when removing the hight and width for svg with no css overriding those styles it is breaking.
If i keep the dimensions: true, then i can't override the height and width with css.
Any suggestions?