首页 文章

Angular 6生成构建抛出语法错误

提问于
浏览
1

我有一个运行良好的项目,当我运行命令 ng build--prod 它成功符合我在我的项目中得到dist文件夹 . 现在我在我的机器上安装了xammp,所以我复制了该文件夹并粘贴在 htdocs 文件夹中 . 所以现在我可以访问该文件夹作为localhost / dist,但应用程序抛出以下错误,应用程序未运行 . 任何人都可以告诉我这个问题究竟是什么 .

GET http://localhost/styles.34c57ab7888ec1573f9c.css 404 (Not Found)
   GET http://localhost/main.d3384476e7e827a9f05c.js 404 (Not Found)

2 回答

  • 2

    默认情况下 baseUrl/ 因此它开始在根文件夹中查找资源 . 您有两种可能的解决方案 .

    • 在根文件夹中部署角度应用程序 .

    • 指定基本URL . 您可以在 index.html 中手动指定基本URL,如 head 标记 <base href="dist/"> 或者您可以在构建angular-cli时指定它具有内置开关 --base-href

    例如: ng build --prod --base-href /dist/

    有关更多信息,请参阅angular-cli documentation

  • 2

    在Angular 6中,您可以在“angular.json”配置中指定baseHref和deployUrl .

    {
          ...
          "projects": {
            "project-name": {
              ...
              "architect": {
                "build": {
                  "options": {
                    "baseHref": "/dist/",
                    "deployUrl": "/dist",
                    ...
                  }
                }
              }
            }
          }
        }
    

    这样,您不必修改index.html,也不需要在命令行中输入额外的参数来构建您的应用程序 .

相关问题