L
L
Ler Den2018-05-15 10:14:28
Angular
Ler Den, 2018-05-15 10:14:28

Angular 5 ng build --prod not seeing scripts?

After the build, scripts and styles are not loaded: Uncaught SyntaxError: Unexpected token <
In the sources of the browser, you can see that instead of js, css, there is index.html.

spoiler
5afa87059e5c4550078542.png

From the server I give the folder In the router I give index.html.
app.use(express.static(__dirname + '/../public'));
router.get('*', function (request, response) {
  response.status(200).sendFile(path.resolve('public/dist/index.html'));
});

Next is angular-cli.json.
spoiler
{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "test-proj"
  },
  "apps": [{
    "root": "src",
    "outDir": "public/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/ngx-toastr/toastr.css",
      "../node_modules/font-awesome/css/font-awesome.min.css",
      "../node_modules/ngx-smart-modal/ngx-smart-modal.scss",
      "scss/styles.scss"
    ],
    "scripts": [],
    "environmentSource": "environments/environment.ts",
    "environments": {
      "dev": "environments/environment.ts",
      "prod": "environments/environment.prod.ts"
    }
  }],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "lint": [{
      "project": "src/tsconfig.app.json"
    },
    {
      "project": "src/tsconfig.spec.json"
    },
    {
      "project": "e2e/tsconfig.e2e.json"
    }
  ],
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "scss",
    "component": {}
  }
}

index.html
<!doctype html>
<html>

<head>
  <meta charset="utf-8">
  <title>Test</title>
  <base href="/">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
</head>

<body>
  <app-root class="app">Loading...</app-root>
</body>

</html>

I want to give the entire public folder, inside of which: dist (angular files, styles, etc.) and uploads (avatars). If you put them in one dist folder, then with each build, the avatars are deleted.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Ler Den, 2018-05-15
@givemoneybiatch

UPDATE
and the folder public/uploadswill not be deleted
Got it.
In my case, you need to run the build like this
https://angular.io/guide/deployment

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question