How to pack CSS files

This article mainly introduces how the CSS file package is packaged, and it has a certain value, and friends needed can be referred to. I hope that everyone has a big gain after reading this article. Let’s take a look at you with everyone.

CSS file package

Loaders is one of the most important features of WebPack, can pass different Loader, thus making specific processing for different file format

Loaders is in the Module module

Simply raised several loaders:

  • can be converted to CSS in the SASS file, and other conversion tools can be used.

  • The code of ES6 or ES7 can be converted into M M Master-compatible JS code.

  • You can convert JSX in React to JavaScript code.
  • TEST: The expression for matching the extension of the processing file, this option is required;

    Use: loader name, you want to use the name of the module, This option must also be configured, otherwise error;
  • include / exclude: Manually add a file (folder) that must be processed (folder) or blocking without processing (optional);
Query: To loaders Provide additional setting options (optional)




Create a CSS folder in the src directory, establish Index.css files in the folder

. /src/css/index.css


body {background-color: red; color: white;}

 CSS fileAfter being established, you need to introduce in the entrance file to pack it, here we introduce in entry.js.  /src/entery.js Add code in the first line in the first line:  
Import CSS from ‘./css/index.css’;


After CSS and introduction, we need to use Loader to parse the CSS file, which is Style-Loader and CSS-Loader.

Style-Loader:

It is used to process URL (), etc. in the CSS file, the URL in NPM: https: / /www.npmjs.com/package/style-loader

Using NPM Install to install: Installing Style-Loader and CSS-Loader must pay attention to their code is different

NPM Install Style-Loader -Save-Dev Css-loader

: It is used to insert CSS into the page STYLE tag. URL in NPM: https://www.npmjs.com/package/css-loader Using NPM Install to install:

NPM Install -save-dev css-loadinger

After both loader downloads, we can configure us to Loaders. Loaders configuration: WebPack.config.js

Module: {Rules: [{Test: /\.css $/, use: [‘style-loader’, ‘css-loader’]}]},

Module is written in 3 types

1, USE: [‘Style-Loader’, ‘Css-Loader’ 2, Loader: [‘Style-Loader’, ‘Css-loader’]
3,

  Use: [{loader: 'style-loader'}, {loader: 'css-loader'}]  

Thank you can read this carefully Article, I hope that Xiaobian shares the CSS file how to pack content help everyone, and also hope that everyone will support Tumi clouds, pay attention to Tumi Cloud Industry Information Channel. If you encounter problems, you will find Tumi clouds, and the detailed solution is waiting for you to learn. !

© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment