what is webpack.
Code splitting
Webpack has two ways of organizing the module dependencies, synchronous and asynchronous. Asynchronously relies as a split point to form a new block. After the dependency tree has been optimized, each asynchronous chunk is packaged as a file. The
Loader
Webpack itself only handles native JavaScript modules, but the Loader converter can convert various types of resources into JavaScript modules. In this way, any resource can be a module that Webpack can handle.
Intelligent Parsing
Webpack has an intelligent parser that can handle almost any third-party library, regardless of whether they are in the form of CommonJS, AMD, or normal JS files. Even when loading dependencies, the dynamic expression require ("./templates/" + name + ". Jade") is allowed. The
plug-in system
Webpack also has a feature-rich plug-in system. Most of the content features are based on this plug-in system, and you can develop and use open source Webpack plug-ins to meet a wide range of requirements. The
Quick Run
Webpack uses asynchronous I/O and multi-level caching to improve operational efficiency, which enables Webpack to compile quickly and incrementally with incredible speed.
summarizes its main advantages:
1. Load modules on demand, lazy loading on demand, and then incrementally update 2.webpack when actually using some modules to write scripts in CommonJS form, but support for Amd/cmd is also comprehensive, Facilitates code migration for legacy projects. 3. Can be modularized not only JS, can handle various types of resources. 4. Easy to develop, can replace part of GRUNT/GULP work, such as packing, compression confusion, picture turn base64 etc. 5. Strong extensibility, plug-in mechanism perfect
installation
first to install node. js, node. JS comes with Package Manager npm
Install Webpack
with NPM
# NPM Install webpack-g////Global Installation
At this point Webpack has been installed in the global environment, can be viewed from the command line webpack-h the relevant instructions
Typically we install Webpack to project dependencies so that you can use the local version of Webpack
Common commands
NPM Init This command will guide you through the creation of a package.json, including information about the author of the release, to help you contract. The dependencies of the packages later installed will also be reflected in the Package.json.
NPM Install executes this command directly and installs each dependent package according to the Package.json configuration in the current directory. The
npm install [module] installs this module in the current directory. Detects if the module exists in the Node_module folder and is not installed.
npm Install [module]-G is installed on a global module. Packages that are installed in global mode are automatically registered to the system variable path.
npm Install [module]--save-dev installs this module in the current directory, but is only used at development time. Under the "Devdependencies" of the package, it means that it is only used at development time.
Go to project directory
Identify existing Package.json and do not create on NPM init
# NPM Install Webpack--save-dev, installed into your project directory
#npm Run Webpack (running the project is to write the Webpack command to the scripts tag of Package.json, and the principle is to use the Webpack command to package. )
If you want to use the Webpack development tool, to install the Webpack-dev-server server separately, you do not have to execute the following command without the development tools.
# NPM Install Webpack-dev-server--save-dev
can use
#webpack-dev-server
Start
webpack Build Command
Common parameters of Webpack
$ webpack--config webpack.min.js//Another configuration file
$ webpack--display-error-details//Display exception information
$ webpack--watch//monitor changes and automatically pack
$ webpack-p//Compression obfuscation script, this is very very important.
$ webpack-d//Generate map Map file to tell which modules were eventually packaged
As the project grows, the compilation process may grow longer, so we can show some progress bars and add color to achieve more friendly output. We can use the following command to achieve the goal:
$ webpack--progress--colors
Start the server
$ webpack-dev-server--progress--colors
Reference Http://www.cnblogs.com/zhengjialux/p/6376501.html?utm_source=itdadao&utm_medium=referral