3

Anybody can help me?

How to build only one bundle.js with angular 8 ? Lots of javascript files were created when I executed "npm run build". (e.g main.js/runtime.js/polyfills.js/...)

I hope that all of them(main.js/runtime.js/polyfills.js/) can output to bundle.js

Here is my packages.json:


{
  "name": "buy-me",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build --prod --aot --build-optimizer --base-href /buyme/ --deploy-url /buyme/",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular-devkit/core": "^8.0.1",
    "@angular/animations": "^8.0.0",
    "@angular/common": "^8.0.0",
    "@angular/compiler": "^8.0.0",
    "@angular/core": "^8.0.0",
    "@angular/forms": "^8.0.0",
    "@angular/platform-browser": "^8.0.0",
    "@angular/platform-browser-dynamic": "^8.0.0",
    "@angular/router": "^8.0.0",
    "core-js": "^3.1.3",
    "ngx-markdown": "^8.0.1",
    "rxjs": "^6.5.2",
    "rxjs-compat": "^6.5.2",
    "tslib": "^1.9.0",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.800.1",
    "@angular/cli": "^8.0.1",
    "@angular/compiler-cli": "^8.0.0",
    "@angular/language-service": "^8.0.0",
    "@types/jasmine": "~3.3.13",
    "@types/jasminewd2": "~2.0.6",
    "@types/node": "~12.0.4",
    "codelyzer": "^5.0.1",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-cli": "~2.0.0",
    "karma-coverage-istanbul-reporter": "^2.0.5",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.2",
    "protractor": "~5.4.2",
    "ts-node": "~8.2.0",
    "tslint": "~5.17.0",
    "typescript": "^3.4.5"
  }
}

I tried but output files like main.js, polyfills.js, runtime.js and so on, I hope that these can be concat one bundle.js.

user11581819
  • 31
  • 1
  • 4

1 Answers1

1

With Angular 8 you don't have to bundle those files together. But if you want, the following steps will help you with that:

  1. Install concat package into your project
  2. Add the following lines to your package.json's "scripts" section:
"concat:es-5": "concat -o ./dist/ng-test-proj/bundle-es5.js ./dist/ng-test-proj/main-es5.*.js ./dist/ng-test-proj/polyfills-es5.*.js ./dist/ng-test-proj/runtime-es5.*.js",
"concat:es-2015": "concat -o ./dist/ng-test-proj/bundle-2015.js ./dist/ng-test-proj/main-es2015.*.js ./dist/ng-test-proj/polyfills-es2015.*.js ./dist/ng-test-proj/runtime-es2015.*.js",
"build:prod": "ng build -c production",
"build:prod:bundle": "npm run build:prod && npm run concat:es-5 && npm run concat:es-2015",

Now you can execute "npm run build:prod:bundle" in a terminal and you will get two bundle files. As a last step, your HTML file should be updated (it should has links to those bundles if you want to use them instead of original files).

Vitalii Ilchenko
  • 578
  • 1
  • 3
  • 7