Webpack entry and Output configuration properties

Source: Internet
Author: User

1, entry

Three ways to configure entry:

(1) Passing a string:

Single entry syntax: Passing a string
Entry: './src/js/main.js ',

(2) passing an array

Multiple primary portals (Multi-main entry) will be created and their dependency-oriented (graph) to a "chunk".

Entry: ['./src/js/main.js ', './src/js/a.js '],

example, the Webpack.config.js file is:

  { Span style= "color: #008000;" >//  packaging portal  entry: ['./src/js/main.js ', './src/js/a.js '  //        filename: ' Bundle.js '  //   path: __dirname, FileName:  './dist/js/bundle.js '     }}

Execute command:

NPM Run Webpack

The effect merges the file into a file, as follows:

(3) Passing objects

The Webpack.config.js file is:

Module.exports = {    //Packing Entranceentry: {main:'./src/js/main.js ', A:'./src/js/a.js '    },    //the packaged fileoutput: {//no __dirname will be an error .        //Path:__dirname + './dist/js ',        //filename: ' bundle.js '        //Error above 2 rows windowpath: __dirname,//Note: Use [name] to ensure that each file name is not duplicatedFileName: './dist/js/[name].js '    }}

Attention:

You should use the following substitution methods to ensure that each file name is not duplicated.

[name]Replaced by the name of the chunk.

[hash]Replaced by a hash of the compilation life cycle.

[chunkhash] replaced by the chunk hash .

2. Output

output.filename

Specifies the name of each output file for the hard drive. You cannot specify an absolute path here!

File Hash code:

Module.exports = {    //Packing Entranceentry: {main:'./src/js/main.js ', A:'./src/js/a.js '    },    //the packaged fileoutput: {//no __dirname will be an error .        //Path:__dirname + './dist/js ',        //filename: ' bundle.js '        //Error above 2 rows windowpath: __dirname,//Note: Use [name] to ensure that each file name is not duplicatedFileName: './dist/js/[name]-[hash].js '    }}

Execute command:

NPM Run Webpack

Results:

[hash] Each file hash is the same, the hash of the file is a packaged hash.

Module.exports = {    //Packing Entranceentry: {main:'./src/js/main.js ', A:'./src/js/a.js '    },    //the packaged fileoutput: {//no __dirname will be an error .        //Path:__dirname + './dist/js ',        //filename: ' bundle.js '        //Error above 2 rows windowpath: __dirname,//Note: Use [name] to ensure that each file name is not duplicatedFileName: './dist/js/[name]-[chunkhash].js '    }}

Using [Chunkhash] file hash is different, and packaging hash is not the same, where the hash is the MD5 value of the file .

Webpack entry and Output configuration properties

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.