access SASS values ($colors from variables.scss) in Typescript (Angular2 ionic2)

后端 未结 6 1216
醉梦人生
醉梦人生 2020-11-27 05:51

In Ionic 2, I would like to access the $colors variables from the file \"[my project]\\src\\theme\\variables.scss\".

This file contains:



        
6条回答
  •  庸人自扰
    2020-11-27 06:14

    In Windows, I used the following taken from Bersling's answer.

    npm i --save-dev ruoqianfengshao/scss-to-json
    
    npm i --save-dev node-sass
    
    "scripts": {
    ...
        "scss2json": "echo export const SCSS_VARS =  > .\\src\\app\\scss-variables.generated.ts && scss-to-json .\\src\\app\\_variables.scss >> .\\src\\app\\scss-variables.generated.ts"
    }
    
    npm run scss2json
    
    import {SCSS_VARS} from './scss-variables.generated';
    ...
    console.log(SCSS_VARS['$color-primary-1']);
    

提交回复
热议问题