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
Table of contents 01 CMD 02 ENTRYPOINT 03 WORKDIR...
Disable right-click menu <body oncontextmenu=s...
background As the company's sub-projects incr...
Please handle basic operations such as connecting...
In the project, we often encounter the problem of...
1. Download https://dev.mysql.com/downloads/mysql...
This article shares the specific code of JavaScri...
Core SQL statements MySQL query statement that do...
This article records the detailed tutorial of MyS...
Introduction to DNMP DNMP (Docker + Nginx + MySQL...
Table of contents Case scenario Solving the probl...
After the National Day holiday, did any of you fi...
Preface The project requirement is to determine w...
When we write some UI components, if we don't...
Table of contents 1. Baidu Map API Access 2. Usin...