Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Merge all bundle files into a single js in angular application using webpack?

I want to understand how to merge multiple bundle.js files like main.bundle.js, scripts.bundle.js etc.(5 in number) into a single bundle.js file and make the reference in the index.html created. I am using angular-cli which uses webpack in turn.

I was able to merge the files using a separate npm module but not using webpack configuration.

like image 528
Jyotirmoy Pan Avatar asked Jan 28 '18 14:01

Jyotirmoy Pan


1 Answers

You determine what Webpack does and how it does it with a JavaScript configuration file, webpack.config.js. Do this

entry: {
  app: 'src/app.ts',
  vendor: 'src/vendor.ts'
},

output: {
  filename: 'app.js'
}

Both app.ts and vendor.ts will be merged into app.js . If you want to keep them seperate do

entry: {
  app: 'src/app.ts',
  vendor: 'src/vendor.ts'
},

output: {
  filename: '[name].js'
}

Hope this helps.

like image 163
RajDev Avatar answered Oct 03 '22 09:10

RajDev