Angular网站部署问题

时间:2018-01-06 07:15:43

标签: javascript angular azure angular-cli

我使用Angular构建了一个网站。我是一个相当基本的Angular用户,但我的应用程序处于我目前满意的状态。在整个开发过程中,我总是使用ng serve来测试和调试我的应用程序。

dist在ng buildng build --prod>上成功编译。运行ng serve --prod也可以正常运行。但是,当我尝试通过dist文件夹中的index.html页面打开应用程序时(在构建时使用-- bh . flag,我得到两个非常相似的错误之一)

  

错误:未捕获(在承诺中):SecurityError:无法执行   ' replaceState' on' History':带URL的历史状态对象   '文件:/// C:/用户/ quent /网站/ PersonalWebApp / DIST /'不可能是   在原文' null'的文档中创建和URL   '文件:/// C:/Users/quent/website/PersonalWebApp/dist/index.html' ;.   错误:无法执行' replaceState'历史'历史状态   对象与URL' file:/// C:/ Users / quent / website / PersonalWebApp / dist /'   无法在原始文档中创建' null'和URL   '文件:/// C:/Users/quent/website/PersonalWebApp/dist/index.html' ;.

页面无法正确获取图像时也会出现一个错误

  

无法加载资源:net :: ERR_FILE_NOT_FOUND

所以,这让我相信这是一个Angular问题,而不是部署问题。作为参考,当我尝试部署到Azure时,我得到一个无法加载资源:控制台中的服务器错误,并在页面上显示无法获取/

我包含了我的angular-cli.json文件以供参考。如果这还不足以帮助我开始调试此问题,请告诉我。非常感谢!

我的.angular-cli.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "personal-web-app"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "favicon.ico",
        "web.config"
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "app",
      "styles": [
        "styles.scss"
      ],
      "scripts": [
        "../node_modules/jquery/dist/jquery.js",
        "../node_modules/hammerjs/hammer.min.js",
        "../node_modules/tether/dist/js/tether.js",
        "../node_modules/bootstrap/dist/js/bootstrap.js"
      ],
      "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",
      "exclude": "**/node_modules/**"
    },
    {
      "project": "src/tsconfig.spec.json",
      "exclude": "**/node_modules/**"
    },
    {
      "project": "e2e/tsconfig.e2e.json",
      "exclude": "**/node_modules/**"
    }
  ],
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "scss",
    "component": {}
  }
} 

1 个答案:

答案 0 :(得分:0)

不是一个有角色的人,但您可能需要通过Web服务器提供ng build --prod生成的静态文件,而不是仅仅在浏览器中打开它们。后者通常不是你想要的,因为当协议为file时,存在一系列限制(来源null,它通过同源策略有很多含义,有限制跨站点XHR /获取请求等)。

通过网络服务器提供一些静态文件的便宜方式是通过python3 -m http.server 8080提供http://localhost:8080上的文件。