How to use Less with Angular 2?

前端 未结 4 904
死守一世寂寞
死守一世寂寞 2021-02-05 04:47

I would like to know how I can add less compiling to my Angular 2 project. Because each component has its own .css file (which now will be a .less file) I am not su

4条回答
  •  醉梦人生
    2021-02-05 05:43

    New project

    You can use the --style flag to set a CSS preprocessor

    ng new my-app --style less
    

    Existing project

    1. If you have an existing project, then you can edit .angular-cli.json file and set defaults.styleExt value to less. Or you can use simply use: ng set defaults.styleExt less
    2. Rename a component's CSS file from mycomp/mycomp.component.css -> mycomp/mycomp.component.less
    3. Update styleUrls in mycomp/mycomp.component.ts, e.g. styleUrls: ['./mycomp.component.css'] -> styleUrls: ['./mycomp.component.less']

    Resource

提交回复
热议问题