[英]define a global sass variable with angular-cli
在我的項目中,我需要注入一個全局變量,以便在整個應用程序中使用,從環境文件到SCSS文件。
以下的建議,如本 ,因為應用程序包含〜50個不同的可能CONFIGS,在這樣保持這么多的項目是不可能的,我angular.json
僅僅是不可行的。
在我們當前的設置中,使用webpack,我們使用sass-loader
的data
選項來注入從環境文件導入的任何變量。 目前這種角度cli是不可能的 - 使遷移變得不可能。
我們怎樣才能做到這一點?
我結束了succesfuly使用NGX建造加 ,隨后該文章,並使用該webpack.extra.js
:
const webpack = require('webpack');
const configs = require('./src/configs');
module.exports = {
plugins: [new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)],
resolve: {
modules: ["node_modules"],
},
module: {
rules: [
{
test: /\.scss$/,
use: [
{
loader: 'sass-loader',
options: {
sourceMap: true,
includePaths: ["src/ng1/assets/sass"],
data: `
$templateTheme: ${configs.templateTheme};
`,
},
},
],
},
],
},
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.