Webpack Summary and Spinach website rental

Source: Internet
Author: User

Webpack is a spinach website rental (e-217-1793-408) gulp almost automatic building tools, the function is still very powerful, able to handle image compression, can handle JS, can handle those pre-compiled language such as SASS|SCSS, CSS and so on, All thanks to a powerful loader function.

Prepare the article

Webpack is a tool that uses node's NPM package management tool to download and install: NPM install-g--save-dev webpack similar to this.

It mainly includes files: Webpack.config.js, Package.json (initialization automatically generated, there are many version related information, including the installation of loaders, etc.), import files, export files.

Inside the Webpack.config.js, the main code framework:

Const PATH = require (' path ');
Const Extracttextplugin = require (' Extract-text-webpack-plugin ');
?
Module.exports = {
? ? Entry: './src/main.js ',
? ? Output: {
? ? ? ? FileName: ' Bundle.js ',??????? The file name of the output
? ? ? ? Path:path.resolve (dirname, ' build ')//The directory where the output file resides
? ? },
? ? Devserver: {//Detect code changes and automatically recompile and refresh the browser automatically
? ? ? ? ContentBase:path.resolve (
DirName, ' build ')//Set the root directory of the static resource
? ? },
? ? Module: {//How to work with different types of modules in a project
? ? ? ? Rules: [//To specify how to handle modules when different modules are created.
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Test:/(. jsx|. JS) $/,
? ? ? ? ? ? ? ? Use: {
? ? ? ? ? ? ? ? ? ? Loader: "Babel-loader",
? ? ? ? ? ? ? ? ? ? Options: {
? ? ? ? ? ? ? ? ? ? ? ? Presets: [
? ? ? ? ? ? ? ? ? ? ? ? ? ? "Env", "React"
? ? ? ? ? ? ? ? ? ? ? ? ]?
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? },
? ? ? ? ? ? ? ? Exclude:path.resolve (__dirname, ' node_modules '),
? ? ? ? ? ? ? ? Include:path.resolve (__dirname, ' src '),
? ? ? ? ? ? },
? ? ? ? ? ? {//css individually packaged
? ? ? ? ? ? ? ? Test:/.scss/,
? ? ? ? ? ? ? ? Use:ExtractTextPlugin.extract ({
? ? ? ? ? ? ? ? ? ? Use: [{
? ? ? ? ? ? ? ? ? ? ? ? Loader: "Css-loader"
? ? ? ? ? ? ? ? ? ? },{
? ? ? ? ? ? ? ? ? ? ? ? Loader: ' Sass-loader '
? ? ? ? ? ? ? ? ? ? }],
? ? ? ? ? ? ? ? ? ? Fallback: "Style-loader"
? ? ? ? ? ? ? ? })
? ? ? ? ? ? },
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Test:/.css$/,
? ? ? ? ? ? ? ? Use:ExtractTextPlugin.extract ({
? ? ? ? ? ? ? ? ? ? Use: [' Css-loader '],
? ? ? ? ? ? ? ? }),
? ? ? ? ? ? },
? ? ? ? ? ? {
? ? Test:/. (png|jpg) $/,
? ? Loader: ' url-loader?limit=8192 ',
? ? }
? ? ? ? ]
? ? },
? ? Plugins: [
? ? ? ? New Extracttextplugin ({
? ? ? ? ? ? FileName: ' Main-page.css ',
? ? ? ? }),
? ? ]
};

Webpack Summary and spinach website rental

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.