About Webpack compiling scss files

Source: Internet
Author: User

CSS loader files are usually used with extract-text-webpack-plugin, we can write the scss file in the SRC directory of the source file, and then compile the CSS file into the output directory public by Webpack. This directory is the directory that our site needs to Reference.

1 varWebpack = require (' webpack '));2 varHtmlwebpackplugin = require (' html-webpack-plugin '));3 varExtracttextwebpackplugin = require (' extract-text-webpack-plugin '));4 varExtractcss =NewExtracttextwebpackplugin ("css/[name].css");//The parameter here is to configure the compiled CSS path and file name, relative to the path option in output5 varPath = require (' path ');6Module.exports = {7 resolve:{8extentions:["", ". scss"]9     },Ten entry:{ oneMain:__dirname + '/app/main.js ', aIndex:__dirname + '/app/index.js ' -     }, - output:{ thePath:__dirname + '/public ',//HTML files generated by the Htmlwebpackplugin plugin are stored under this directory -Filename: '/js/[name].js ',//compile the generated JS file to the root directory under the JS directory, if the JS directory does not exist automatically created -     }, - module:{ + loaders:[ -{test:/\.scss$/,loader:extractcss.extract ([' css ', ' sass ')])} +         ] a     }, at sassloader:{ -Includepaths:[path.resolve (__dirname, './app/css '))] -     }, - plugins:[ -         NewHtmlwebpackplugin ({title: ' Custom title2 ', template:__dirname + '/public/tempindex.html '}), - Extractcss in     ] -}

Note:new Extracttextwebpackplugin ("css/[name].css"), If the [name] placeholder is used, only the portal file referencing the Scss file is compiled, and the resulting CSS file name corresponds to the entry File.

If more than one portal file introduces the same scss file, and the entry property is configured with the vendor object, a vendor.css file is generated, and the source code for the Vendor.css file is the Scss file that the portal file references together ( Webpack.optimize.CommonsChunkPlugin can not only extract the common JS file can also extract the common CSS files, if not configured vendor, respectively, generate multiple CSS files with the same name as the portal File.

If more than one portal file refers to a different scss file, regardless of whether the entry property has a configuration vendor object, multiple CSS files with the same name corresponding to the portal file are Generated.

The [name] placeholder is typically used, and if only one of the portal nodes references the Scss file and only one scss file is referenced, you can specify any name without a placeholder.

About Webpack compiling scss files

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.