admin管理员组文章数量:1287645
Using rollup and the postcss plugin, I am able to inject CSS into my bundle. However, my CSS references some image files e.g. background-image: url(./images/my-image.svg);
.
How can I configure postcss/rollup to replace instances of CSS url(...)
with data URIs and thereby embed the SVGs inside of the bundle?
Using rollup and the postcss plugin, I am able to inject CSS into my bundle. However, my CSS references some image files e.g. background-image: url(./images/my-image.svg);
.
How can I configure postcss/rollup to replace instances of CSS url(...)
with data URIs and thereby embed the SVGs inside of the bundle?
1 Answer
Reset to default 11You could use postcss-url plugin to achieve this.
Install the postcss-url
plugin to your project and add it to the postcss plugins array in your rollup config.
const url = require('postcss-url');
const postcss = require("rollup-plugin-postcss");
export default {
plugins: [
postcss({
plugins: [
url({
url: "inline", // enable inline assets using base64 encoding
maxSize: 10, // maximum file size to inline (in kilobytes)
fallback: "copy", // fallback method to use if max size is exceeded
}),
],
}),
],
};
You can customize the fallback mechanism based on your needs.
本文标签: javascriptHow to replace url() in rollup39d CSS with data URIStack Overflow
版权声明:本文标题:javascript - How to replace url(...) in rollup'd CSS with data URI? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741244790a2364667.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论