在我的 Angular 项目中,我需要在 index.html 文件中使用 PHP。我已经将其重命名为index.php 并更新了 angular.json 以在索引属性中使用index.php。
我的问题是,运行后ng build
命令,dist目录下生成的index.php文件中的PHP代码被注释掉。
<!--?php
$websiteCode = getenv('SITE_CODE');
?--><!DOCTYPE html><html lang="en"><head>
<meta charset="utf-8">
<title>ClientPortal</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" href="styles.31d6cfe0d16ae931b73c.css"></head>
<body>
<!--?=$websiteCode?-->
<app-root></app-root>
<script src="runtime.f3b55109ab97bda870bd.js" defer></script><script src="polyfills.a58f45ef9ccddb12523d.js" defer></script><script src="main.6629fcd1d3960ef0deb9.js" defer></script>
</body></html>
是否有我需要更新或指定的配置,以便 PHP 代码不会被注释?我正在使用 Angular 12。
这在我现有的使用 Angular 7 的 Angular 项目中运行良好。
这种行为似乎是一个错误。这是由 CSS 优化器引起的。禁用inlineCritical
修复了该问题(请参阅https://angular.io/guide/workspace-config#styles-optimization-options https://angular.io/guide/workspace-config#styles-optimization-options).
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"fubar": {
"projectType": "library",
...
},
"acme": {
"projectType": "application",
"schematics": { ... },
...
"architect": {
"build": {
...
"configurations": {
"production": {
...
"optimization": { <-- ADDING THIS HAS SOLVED THE ISSUE FOR ME.
"styles": {
"inlineCritical": false
}
}
},
"development": {
...
}
},
"defaultConfiguration": "..."
},
"serve": {
...
},
"extract-i18n": {
...
},
"test": {
...
}
}
}
},
"defaultProject": "acme"
}
重要的是要注意构建时间的差异,这表明禁用的优化不是一项简单的任务。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)