-
-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using svg as background-image does not work #30
Comments
A workaround for this is putting the icons in |
@studnitz I'll look into this soon |
This is a great request – I am facing the same problem right now. A nice approach used by vue-svg-loader is allowing the use of I think that would be better if we could use <template>
<div>
<InlineSVG />
<div class="external-svg" />
</div>
</template>
<script>
import InlineSVG from './public/inline.svg';
export {
components: {
InlineSVG,
},
};
</script>
<style>
.external-svg {
background-image: url("./public/external.svg?external"); // Note the `?external` query string
}
</style> |
Here is another workaround from the used library: |
Here it is way to resolve them.
|
The workaround from egoist/svg-to-vue-component#18 (comment) could be "translated" from webpack-chain syntax to normal webpack config syntax. If I have some spare time, I'll give it a shot. However, I'm accepting a PR (feature + one test) that fixes the issue. |
@manniL But the approach mentioned in egoist/svg-to-vue-component#18 (comment) would solve only styling imported from .css files. What about |
@3b3ziz True, ideally an |
My approach to this is (tested on Nuxt v2.3 & v2.8) is: // nuxt.config.js
extend(config) {
const svgRule = config.module.rules.find(rule =>
rule.test.test('.svg')
);
svgRule.test = /\.(png|jpe?g|gif|webp)$/;
config.module.rules.push({
test: /\.svg$/,
oneOf: [
{
resourceQuery: /inline/,
loader: 'file-loader',
query: {
name: 'assets/[name].[hash:8].[ext]'
}
},
{
loader: 'vue-svg-loader',
options: {
// Optional svgo options
svgo: {
plugins: [{ removeViewBox: false }]
}
}
}
]
});
} Solves SVG in |
just for the record, since @3b3ziz has modified it himself 👍 , the good way is now :
|
When you use the default options and rules given here, svg paths cannot be used in CSS
background-image: url()
anymore.Example:
Output
Expected
This would require https://github.com/bhovhannes/svg-url-loader to work
The webpack config could then look like that, I tried to make it work locally, but somehow the resulting SVG data gets escaped (guess this is some kind of nuxt XSS protection).
You could use it then like this:
The text was updated successfully, but these errors were encountered: