How to use normalize.css using npm install with webpack?

后端 未结 5 1443
情话喂你
情话喂你 2021-02-03 17:09

I am using webpack with ReactJS and trying to figure out how to using normalize.css after npm installing it (https://necolas.github.io/normalize.css/).

Is the normalize

5条回答
  •  渐次进展
    2021-02-03 17:42

    Once you import or require it will be included by Webpack unless you set it not to. For example:

    Note: I’m using Webpack 2.

    module: {
        rules: [ // from 'loaders' to 'rules'
            {
                test: /\.js$/,
                loader: 'babel-loader',
                exclude: /node_modules/,
            },
            {
                test: /\.sass$/,
                exclude: /node_modules/,
                loader: ExtractTextPlugin.extract({
                  fallbackLoader: 'style-loader',
                  loader: ['style-loader','sass-loader']
                })
            }
        ]
    }
    

    The exclude property will take care of that.

    Example:

    // public/assets/style.scss
    @import 'substyle1';
    @import 'substyle1';
    
    body {
      background-color: red;
    }
    
    // src/index.js -> entry file
    import '../public/assets/style.scss';
    // Webpack will know that you are importing your SCSS / SASS file
    

    Hope this helps.

提交回复
热议问题