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

JavaScript Webpack

番长猴子古一

2020-03-24

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

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

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

第3365篇《如何将npm install与webpack一起使用normalize.css?》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

2个回答
古一凯 2020.03.24

添加:如果您使用的是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"
            ]
        }
    ]
};
LGil 2020.03.24

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.

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android