简体   繁体   English

尝试使用css-loader时出错

[英]Error when trying to work with css-loader

While developing with Reactjs, I have problem with css-loader. 在使用Reactjs开发时,我对css-loader有问题。 Basically, this is my webpack.config : 基本上,这是我的webpack.config

{
test: /\.css$/,
exclude: /node_modules/,
loader: 'style-loader!css-loader?localIdentName=[name]__[local]__[hash:base64:5]&modules&importLoaders=1&sourceMap!postcss-loader',
}, {
test: /\.css$/,
include: /node_modules/,
loaders: ['style-loader', 'css-loader'],
},

And this is how I implement the css : 这就是我实现CSS的方式:

import styles from './Home.css';
.
.
.
<FormControl type="text" className={styles['input-search']}/>

This is my Home.css 这是我的Home.css

.input-search{
width: 500px;
}

I'm using Hasnode's mern-starter 我正在使用Hasnode的mern-starter

But there are no css is loaded. 但是没有CSS加载。 What should I do ? 我该怎么办 ?

在此处输入图片说明

在此处输入图片说明

Just change it to this and see if it works: 只需将其更改为此,看看它是否有效:

{
    test: /\.css$/,
    loader: 'style-loader!css-loader'
}

If that works, then add your exclude: /node_modules/ and finally, if that works, then add all your crazy ?localIdentName=[name]__[local]__[hash:base64:5]&modules&importLoaders=1&sourceMap additions. 如果exclude: /node_modules/ ,则添加您的exclude: /node_modules/最后,如果exclude: /node_modules/ ,则添加所有疯狂的?localIdentName=[name]__[local]__[hash:base64:5]&modules&importLoaders=1&sourceMap附加内容。

Also consider adding a resolve section to your config: 还可以考虑在您的配置中添加一个resolve部分:

resolve: {
    modules: [
      path.join(__dirname, '../src/components'),
      'node_modules'
    ],
    extensions: ['.js', '.jsx', '.css']
  },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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