webpack loads css files and its configuration
const path = require('path'); module.exports = { // In the configuration file, manually specify the entry file and export file mode:'development', // This attribute needs to be added in the webpack4.x version entry:'./src/main.js', // Entry file output:{ // Export file path:path.resolve(__dirname,'dist'), // Specify where the packaged files should be output (note: the path must be an absolute address) filename: 'bundle.js' //Specify the file name of the output file}, module:{ rules:[ {test:/\.css$/ , use:['style-loader' , 'css-loader']} ] } } Test indicates what type of file we want to process, and each item in use is the loader required to process that type of file. Note: The css-loader is used to let the main.js file load the css file, while the style-loader is used to add the module's exports as styles to the DOM. Some people may have questions here: according to this function, the file should be loaded first and then added to the DOM as a style, so the order in the array should not be like this. I am here to tell you clearly that your idea is not wrong, but webpack is very peculiar in that it loads the loader from the last element of the array, from right to left. After setting the dependency, downloading the loader and configuring it, we will find that the styles in the CSS file appear after running it. Summarize The above is the webpack loading css file and its configuration method introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you! |
<<: How to use Element in React project
>>: Pagination Examples and Good Practices
Preface This article mainly introduces the releva...
1. overflow:hidden overflow hidden If overflow:hi...
This article example shares the specific code of ...
Due to company requirements, two nginx servers in...
As a basic element of a web page, images are one ...
flex layout Definition: The element of Flex layou...
In most cases, MySQL does not support Chinese whe...
Environmental requirements: IP hostname 192.168.1...
Table of contents Preface Implementation ideas Im...
Preface As you know, Linux supports many file sys...
Table of contents 1. Overview 2. Application Exam...
1. Create a MySQL database 1. Create database syn...
One time we talked about the dice rolling game. A...
This article shares the specific code for impleme...
Find the problem Today, when I tried to modify th...