Front-End Engineered Webpack (I.)

Source: Internet
Author: User

Basic usage of Webpack

1.app.js Introduction Module

Import Modulelog  from './module.js'//introduced modulelog from./module.js

2.module.js Export Module

Export Default function      (){}; Export function () {}

3. Packaging

App.js dist/bundle.js //Package entry file app.js  Export file ./dist/bundle.js

  Here to use Webpack this command to $ npm i-g webpack

Webpack.config.js the most settings

Const PATH = require (' path '); Built-  in module =  {'./app.js ',//ingress  output: {//Exit        Path:path.join (__dirname,dist),/ /With this method  the delimiter of the path (with \ or/) will        not error './dist ',//path is the output directory         used to store the packaged file ' Bundle.js '//PUBLICP Ath make reference directory for resource file   },
}

After configuring the above, only need to enter Webpack to implement packaging in the folder to generate the entity file

$ webpack

webpack-dev-server Hot Load added to module.export inside the development of this module to use to $ NPM i-d webpack-dev-server

devserver: {  ' dist ',//output bundle.js place   3000//port number },

Add a script face in the configuration Package.json

Dev: ' Webpack-dev-server '

Do not generate local files after packaging is present in memory

$ npm Run dev//Enter locallhost:3000 in the browser to access

After setting the Publicpath in the devserver output there is no need to set the Path and Publicpaht, then the page introduced is not the local folder inside the Bundle.js, but the Fillename attribute is in effect You can also set devserver inside the Publicpath to change the build directory here to notice a little devserver publicpath to indicate that the current path to use a '/' expression (the author is also a beginner this Something tried all night ... However this attribute is not very important)

Front-End Engineered Webpack (I.)

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.