如何将npm install与webpack一起使用normalize.css?

我正在将Webpack与ReactJS一起使用,并试图找出如何在npm安装它之后使用normalize.css(https://necolas.github.io/normalize.css/)。

npm安装后是否立即应用了normalize.css?如果需要,我将如何对其进行编辑?

预先谢谢您,一定会投票并接受答案

古一凯2020/03/24 14:23:18

添加:如果您使用的是WebPack 4,则无法导入normalize.less,请尝试normalize.css。

@import "../node_modules/normalize.css/normalize.css";

我的规则是:

module: {
    rules: [{
            test: /\.css$/,
            use: [MiniCssExtractPlugin.loader,
                "css-loader"
            ]
        },
        {
            test: /\.less$/,
            use: [
                MiniCssExtractPlugin.loader,
                "css-loader",
                "less-loader"
            ]
        }
    ]
};
LGil2020/03/24 14:23:18

First, install or download normalize.css from GitHub.I would recommend download it.Then, There are then 2 main ways to make use of it.

Approach 1: use normalize.css as a starting point for your own project’s base CSS, customising the values to match the design’s requirements.

Approach 2: include normalize.css untouched and build upon it, overriding the defaults later in your CSS if necessary.

i.e Just put these downloaded files into the project folder and add link to it by link tag

link rel="stylesheet" type="text/css" href="normalize.css"

NOTE href content should point to the folder where normalize is stored.