Webpack3 Finishing (first section/full)

Source: Internet
Author: User

One, CSS files packaged into JS ( three ways of loader)

 //  The first way: use using directly.         module: {rules: [{test: /\.css$/ ' Style-loader ', ' css-loader '  //  The Third way: using the Use+loader notation:   module: {rules: [{test: /\.css$/ "Style-loader" }, {loader:  "Css-loade R "}]}]}  

Second, compression JS code (although UGLIFYJS is a plug-in, but the Webpack version of the default integration, do not need to install again.) )

Const Path=require (' path '); Const uglify= Require (' Uglifyjs-webpack-plugin '); Module.exports={entry:{entry:'./src/main.js ', //configuration of the ingress file }, output:{ //Export file configuration item path:path.resolve (__dirname,' Dist '),  //The path of the output  filename:' [Name].js '//output file name ([name] means that according to the name of the portal file, packaged into the same name, there are several portal files, you can package a few files)}, module:{ //plug-in for production templates and various functions rules:[{test:/\.css$/, use: ["Style-loader", "Css-loader"]}]}, plugins:[Newuglify ()], devserver:{contentBase:path.resolve (__dirname,' Dist '), //Set basic directory Structure host:' 192.168.0.144 ', //The IP address of the server, you can use IP or localhost (recommended for native IP) compress:true, //service-side compression whether to open port:3000//Configure service port number (not recommended 8080 easy to use)    }}

Note: To perform webpack-dev-server is to use NPM install Webpack-dev-server–save-dev to download the installation. Once downloaded, you need to configure Devserver.
(need to be configured below Package.json below)

 "Scripts": {
"Server": "Webpack-dev-server"
}

After the configuration is saved, enter NPM run server in the terminal to open the server to see the page results. (the corresponding file also has the basic configuration of plug-in in Webpack.prod.conf.js)

CSS automatically joins the prefix plug-in configuration: (The root directory below the psotcss.js for the following configuration):

Module.exports = {    plugins: [        require (' autoprefixer ')    ]}

this one simple Postcss's configuration, introduced the Autoprefixer plugin. Let Postcss have the ability to add prefixes, which adds the corresponding CSS3 attribute prefixes based on can I use. Then configure loader

{
Test:/\.css$/,
Use: [{
Loader: "Style-loader"
}, {
Loader: "Css-loader",
Options: {
Modules:true
}
}, {
Loader: "Postcss-loader"
}]
}

Webpack3 Finishing (first section/full)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.