The last one we will webpack entrance entry , that since there is the entrance, there will be a corresponding export. So in this section we will webpack about the exit output .

output attribute is used to specify webpack how to output, and where the output it creates bundles , and how to name files. Basically the entire application structure will be compiled into the folder of the specified output path. We can configure these processes output field in the configuration file.

output configuration

output is a object object, which contains a series of configuration items, of which the more important ones are filename and path .

  • output.filename : Configure the name of the output file, and specify a string type 060ed480eac2aa. If there is only one output file, it can be written as static and unchanging.
  • output.path : The configuration output file is stored in a local directory, which is an absolute path of type string The absolute path is usually obtained through the path

In the webpack.config.js configuration file, a entry corresponds to a output .

Example:

For example, the following code:

module.exports = {
    entry:'./index.js',
    output:{
        path:__dirname,
        filename:'./bundle.js'
    }
}

The code specifies an entry file index.js for webpack entry attribute. Specify an export file for webpack through the output bundle.js .

When webpack plurality entry time, a entry should correspond to a output , then the output file name to replace the need to use declarations to ensure uniqueness of the filename.

Example:
module.exports = {
  entry: {
    app: './one.js',
    search: './two.js'
  },
  output: {
    path: __dirname + '/dist',
    filename: '[name].js',
  }
}

The final item in the root directory dist folder generated one.js and two.js two bundle file.


知否
221 声望177 粉丝

Skrike while the iron is hot.