当我运行ng build时,我得到了这个index.html文件:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>ApiApp</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>
<script type="text/javascript">
const appData = JSON.parse('<%=json%>');
</script>
<app-root></app-root>
<script type="text/javascript" src="runtime.js"></script>
<script type="text/javascript" src="polyfills.js"></script>
<script type="text/javascript" src="styles.js"></script>
<script type="text/javascript" src="vendor.js"></script>
<script type="text/javascript" src="main.js"></script>
</body>
</html>构建后使用脚本,我将将静态资产推送到一些CDN,因此我实际上希望生成一个类似于以下所示的.html文件:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>ApiApp</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>
<script type="text/javascript">
const appData = JSON.parse('<%=json%>');
</script>
<app-root></app-root>
<script type="text/javascript" src="http://cdn.github.com/runtime.js"></script>
<script type="text/javascript" src="http://cdn.github.com/polyfills.js"></script>
<script type="text/javascript" src="http://cdn.github.com/styles.js"></script>
<script type="text/javascript" src="http://cdn.github.com/vendor.js"></script>
<script type="text/javascript" src="http://cdn.github.com/main.js"></script>
</body>
</html>(是我编的域cdn.github.com)。因此,我可以手动生成这些文件的urls,但我想知道Angular是否允许我们以某种方式配置它?
发布于 2018-12-08 08:04:07
您可以在您的角项目中的angular.json文件中配置它。
{
"projects": {
"<Your Angular Project Name>": {
"architect": {
"build": {
"options": {
"baseHref": "/testapp/",
"deployUrl": "/testapp/",
...
}
}
}
}
}
}deployUrl基本上就是你要找的东西。
要获得可用的构建选项及其描述,可以参考以下链接:https://github.com/angular/angular-cli/wiki/build
https://stackoverflow.com/questions/53680473
复制相似问题