Home > Mobile >  webpack is building a lots of files instead of one
webpack is building a lots of files instead of one

Time:12-27

When building my app with webpack to the ./dist folder, I get a lot of file whereas I'm expecting to have only one. My ./dist folder looks like:

657.main.js
657.main.js.LICENSE.txt
657.main.js.map
726.main.js
main.js
main.js.LICENSE.txt
main.js.map

When I'm expecting:

main.js

My webpack config is the following:

const path = require('path')

module.exports = {
  mode: 'production',
  devtool: 'source-map',
  entry:  './src/index.js',
  output: {
    filename: 'main.js',
    path: path.resolve(__dirname, 'dist'),
    library: 'foobar',
  }
}

When removing all other files except main.js I get errors.

Is there a way to build my app to only one file?

CodePudding user response:

Webpack by default is chucking/code splitting the modules. You can disable/set max number of chunks it by using this plugin:

https://webpack.js.org/plugins/limit-chunk-count-plugin/

  • Related