css - 自定义属性被忽略 : not scoped to the top-level :root element

标签 css angular sass warnings

.angular-cli.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "tensor web"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "app",
      "styles": [
        "styles.scss",
        "../node_modules/firebaseui/dist/firebaseui.css"
      ],
      "scripts": [
      .....
      ],
      "environmentSource": "environments/environment.ts",
      "environments": {
      ....
      }
    }
  ],
  "e2e": {
   .....
  },
  "lint": [
   .....
  ],
  "test": {
   .....
  },
  "defaults": {
   .....
  }
}

张量变量.scss

$body-bg:                   #ecf0f1;

样式.scss

$icon-font-path: '~bootstrap-sass/assets/fonts/bootstrap/';
@import './css/tensor-variables.scss';
@import '~bootstrap-sass/assets/stylesheets/_bootstrap.scss';
@import './css/core/global.scss';
@import './css/core/utils.scss';

@import './css/layout/sidebar.scss';
@import './css/layout/navbar.scss';
@import './css/layout/container.scss';

$fa-font-path: './fonts' !default;
@import '~font-awesome/scss/font-awesome';

// prebuilt Themes
@import "~@angular/material/prebuilt-themes/indigo-pink.css";

app-root.arctic {    
  --app-bg-color: $body-bg;
}

WARNING in ./node_modules/css-loader?{"sourceMap":false,"importLoaders":1}!./node_modules/postcss-loader?{"ident":"postcss"}!./node_modules/sass-loader/lib/loader.js?{"sourceMap":false,"precision":8,"includePaths":[]}!./src/styles.scss (Emitted value instead of an instance of Error) postcss-custom-properties: /Users/ishandutta2007/Documents/Projects/tensorweb/src/styles.scss:8453:3: Custom property ignored: not scoped to the top-level :root element (app-root.arctic { ... --app-bg-color: ... }) NonErrorEmittedError: (Emitted value instead of an instance of Error) postcss-custom-properties: /Users/ishandutta2007/Documents/Projects/tensorweb/src/styles.scss:8453:3: Custom property ignored: not scoped to the top-level :root element (app-root.arctic { ... --app-bg-color: ... }) at Object.emitWarning (/Users/ishandutta2007/Documents/Projects/tensorweb/node_modules/webpack/lib/NormalModule.js:117:16) at /Users/ishandutta2007/Documents/Projects/tensorweb/node_modules/postcss-loader/index.js:131:24 at Array.forEach () at /Users/ishandutta2007/Documents/Projects/tensorweb/node_modules/postcss-loader/index.js:130:31 at @ ./src/styles.scss 4:14-187 @ multi ./src/styles.scss ./node_modules/firebaseui/dist/firebaseui.css

最佳答案

我在使用 React/Webpack 时遇到了类似的问题。所以我添加了 postcss.config.js 文件和下面的代码

const postcssCssNext = require('postcss-cssnext')
const postcssImport = require('postcss-import')

module.exports = {
    plugins: [
        postcssCssNext({
            features: {
                customProperties: {
                    warnings: false
                }
            }
        }),
        postcssImport
    ]
}

关于css - 自定义属性被忽略 : not scoped to the top-level :root element,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48434915/

相关文章:

css - 在IIS7中编译Sass文件

css - 选择第二级的第一个 child

css - 使用 CSS 隐藏/显示在 Chrome 中不显示内容

css - 防止移动设备上的站点导航重叠 header

html - 调整大小时如何使文本相对于图像保持在相同位置?

html - 从 Angular 2 组件访问根 html 标签

angular - 更改垫选择箭头图标

html - 调整大小时如何自动将框移动到底部?

javascript - 如何在 Angular 中按服务器分组

css - 不熟悉 Sass,我认为我的 main.scss 中有一个小语法问题阻止我编译