带有angular-cli的SVG图标系统 [英] SVG icon system with angular-cli
本文介绍了带有angular-cli的SVG图标系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个angular2项目,它是通过angular-cli创建的.在webpack中,有一个加载器可以加载svg sprite,并从svgs列表中生成该sprite.但是,当angular-cli不允许我更改webpack.config时,如何在当前项目中使用此功能?
I have an angular2 project which was created via angular-cli. In webpack there is a loader to load the svg sprite and also to generate that sprite from list of svgs. But how do I can use this functionality in my current project when angular-cli doesn't allow me to change webpack.config?
谢谢.
推荐答案
使用 svg-sprite
1. npm install --save-dev svg-sprite
2.将您的svg放入src/svgs
3.将sprite-config.json
添加到您的项目根目录
Use svg-sprite
1. npm install --save-dev svg-sprite
2. Put your svgs in src/svgs
3. Add sprite-config.json
to your project root
{
"dest": "src/",
"mode": {
"css": {
"dest": "sprites",
"render": {
"scss": {
"dest": "_sprite.scss"
}
}
}
}
}
4.将脚本添加到package.json
"sprites": "svg-sprite --config sprite-config.json src/svgs/*.svg"
5.将@import
添加到主styles.scss
5. Add @import
to your main styles.scss
@import './sprites/sprite';
6.使用npm run sprites
运行脚本
可选:创建一个构建脚本
将此添加到脚本中即可一步构建
6. Run script using npm run sprites
Optional: create a build script
Add this to your scripts to build in one step
"start": "npm run sprites && ng serve",
"build": "npm run sprites && ng build --prod"
这篇关于带有angular-cli的SVG图标系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文