Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify the src location for javascript script tags during ng build

My index.html file post ng build has the below files

<script type="text/javascript" src="inline.bundle.js"></script>
<script type="text/javascript" src="polyfills.bundle.js"></script>
<script type="text/javascript" src="styles.bundle.js"></script>
<script type="text/javascript" src="vendor.bundle.js"></script>

How can I make angular cli prepend 'app' in the src folder location, for example src="/app/vendor.bundle.js"

I would need to make the above change since I am loading all my static assets in dropwizard from a file system location starting with '/app/'

Below is my angular-cli.json for reference

angular-cli.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "web"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "app",
      "styles": [
        "../node_modules/bootstrap/dist/css/bootstrap.min.css",
        "../node_modules/font-awesome/css/font-awesome.min.css",
        "../node_modules/primeng/resources/themes/ludvig/theme.css",
        "../node_modules/primeng/resources/primeng.min.css",
        "styles.css"
      ],
      "scripts": [],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts"
      }
    }
  ],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "lint": [
    {
      "project": "src/tsconfig.app.json"
    },
    {
      "project": "src/tsconfig.spec.json"
    },
    {
      "project": "e2e/tsconfig.e2e.json"
    }
  ],
  "defaults": {
    "styleExt": "css",
    "component": {}
  }
}
like image 903
serah Avatar asked Jul 26 '17 13:07

serah


1 Answers

There is a deployUrl parameter inside your angular-cli.json :

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "web"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "deployUrl": "/app/",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index.html",

your imports will become :

<script type="text/javascript" src="/app/inline.bundle.js"></script>
<script type="text/javascript" src="/app/polyfills.bundle.js"></script>
<script type="text/javascript" src="/app/styles.bundle.js"></script>
<script type="text/javascript" src="/app/vendor.bundle.js"></script>

that's what you want ?

like image 138
Maxouhell Avatar answered Nov 18 '22 22:11

Maxouhell