SVG icon system with angular-cli

徘徊边缘 提交于 2019-12-03 17:06:59

问题


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?

Thanks.


回答1:


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. Add a script to package.json

"sprites": "svg-sprite --config sprite-config.json src/svgs/*.svg"

5. Add @import to your main styles.scss

@import './sprites/sprite';

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"


来源:https://stackoverflow.com/questions/41340133/svg-icon-system-with-angular-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!