Preliminary Webpack Pack

Source: Internet
Author: User

First contact with Webpack, learn how to use Webpack packaging, record the process.

1. Install Webpack in the project root directory

$ NPM Install Webpack--save-dev

2. Create a new Webpack.config.js

3. Install the required loader as needed and configure it in the Webpack.config.js module, such as Load Babel.

$ NPM Install Babel-loader--save-dev

Webpack.config.js file

var webpack = require (' Webpack '); var commonsplugin = new Webpack.optimize.CommonsChunkPlugin (' Common.js '); Module.exports = {//Page entry file Configuration entry: {' A ': './src/a.js ',},//Portal file output config: {path: './build ', filename: ' [name].js '}, Module: {  loaders: [  {test:/\.js|jsx$/, loaders: [' Babel ']},  ]},resolve:{extensions: [', '. js ', '. JSON ', '. Scss '}}

Webpack after a simple installation, look at the project directory

A.js and B.js under SRC

A.js:

var B = require ("./b"); Console.log (B.add);

B.js:

Module.exports.add=function (b) {return a + B;}

Because the previous webpack.config.js has been configured, and then

$ webpack-w

We will find that this file was introduced in build under a a.js,index.html, and the console will output 3.

Simple record, if wrong, we can correct, thank you ha

Preliminary Webpack Pack

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.