How to import css file for into Component .jsx file

后端 未结 3 782

I am trying to use the react-day-pickers component like so but I can\'t figure out how to import the .css file and I keep getting the error:

Module parse fai         


        
相关标签:
3条回答
  • 2021-01-06 19:02

    How are you compiling this? If it's webpack, you'd probably need to bring in the style-loader and include something like this in the module.loaders array in your webpack config:

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

    Update: With the webpack.config.js now provided, we can confirm it needed a change in the module.loaders array. OP was using a less loader and only checking for .less files, so the exact loader object should read:

    {
      test: /\.(less|css)$/,
      loader: 'style!css!less'
    }
    

    As suggested by @Q Liu. Leaving the original bit as if someone comes here with an error importing a .css file, it's likely what they need.

    0 讨论(0)
  • 2021-01-06 19:04

    I used the following in my webpack config and it worked:

    test: /\.css$/,
            use: [
              'style-loader',
              {
                loader: 'css-loader',
                options: {
                  modules: true,
                },
              },
            ],

    0 讨论(0)
  • 2021-01-06 19:07

    JSX is not CSS. In your main HTML file, just add a <link> element to the CSS file, and the DOM generated by React will use it.

    0 讨论(0)
提交回复
热议问题