简体   繁体   中英

Invalid Property Value on css style using imported css file in react

I am trying to style a React Component. To achieve this, I am importing a css file and using className such as indicated in ReactJs Documentation.

I have added a css-loader + style-loader to my webpack.config.js file as described below :

const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  mode: "development",
  entry: "../src/index.js",
  output: {
    path: path.resolve(__dirname, "../dist"),
    filename: "bundle.js",
  },
  devtool: 'inline-source-map',
  devServer: {
    contentBase: '../dist',
    port: 8080
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /(node_modules|bower_components)/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env', '@babel/preset-react']
          }
        }
      },
      {
        test: /\.css$/,
        use: [ 'style-loader', 'css-loader' ]
      }
    ]
  },
  plugins: [new HtmlWebpackPlugin(
    {template: '../src/index.html'}
  )]
}

Here is my App.js React Component :

import React, {Component} from "react"
import "./App.css"

const App = () => (
  <div className="hello-world">Hello World</div>
)

export default App

And my App.css File :

.hello-world{
  color: "#272C35"
}

My css is correctly loaded since the property + value appear in the development tool. But for some reason, the value is marked as incorrect as shown below :

使用不正确的css值捕获导航器检查模式

css文件中的颜色十六进制不需要引号。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM