【问题标题】:Angular X - How to change the path for the compiled JavaScript files in index.html [duplicate]Angular X - 如何更改 index.html 中已编译 JavaScript 文件的路径 [重复]
【发布时间】:2019-12-20 00:14:42
【问题描述】:

我在 Iframe 中使用我的 Angular 应用程序,我希望能够在构建(ng 构建)之后更改 index.html 中 javascript 文件的路径。

这是我用来构建 Angular 应用程序的命令:

npm run env && ng build --aot --prod --environment=prod

完成后,在我的 dist 文件夹中,我有这棵树:

index.html
inline.318b50c57b4eba3d437b.bundle.js
main.d83bd9b8af8c676f706b.bundle.js
and etc

查看 index.html 内部,我们可以看到以下内容:

<body>
...
<script type="text/javascript" src="inline.318b50c57b4eba3d437b.bundle.js"></script>
<script type="text/javascript" src="polyfills.5a5809ec73e38d8a32d3.bundle.js"></script>
<script type="text/javascript" src="scripts.7b67fa96a25429619fd6.bundle.js"></script>
<script type="text/javascript" src="main.d83bd9b8af8c676f706b.bundle.js"></script>
</body>

我想以某种方式更改构建命令,也许有一个我没有看到的标志或任何其他方法来生成 index.html,其中 javascript 文件的路径不同,如下所示:

<body>
...
<script type="text/javascript" src="PathBefore/inline.318b50c57b4eba3d437b.bundle.js"></script>
<script type="text/javascript" src="PathBefore/polyfills.5a5809ec73e38d8a32d3.bundle.js"></script>
<script type="text/javascript" src="PathBefore/scripts.7b67fa96a25429619fd6.bundle.js"></script>
<script type="text/javascript" src="PathBefore/main.d83bd9b8af8c676f706b.bundle.js"></script>
</body>

【问题讨论】:

  • 尝试 ng build --prod --base-href=/PathBefore/
  • 对不起,我忘了还提到我尝试了 --base-href 标志但它不起作用:(
  • @SGalea 这不是我想要的,但它仍然是适合我的解决方法。
  • 您可以在构建本身中使用--output-path
  • 回答可能有点晚了,我在 ng build --prod --deployUrl="PathBefore/" `

标签: javascript angular iframe angular6 ng-build


【解决方案1】:

在构建命令中设置 href base

ng build --base-href /PathBefore/ 

【讨论】:

    猜你喜欢
    • 2020-04-29
    • 2018-08-03
    • 1970-01-01
    • 2020-04-15
    • 1970-01-01
    • 2018-01-20
    • 2011-12-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多