我创建了一个Cordova应用程序,当创建新项目时,简单地提供默认的Angular欢迎页面。在浏览器中它能够正常工作,在Android Studio模拟器上运行它也能够正常工作。
但是当我在我的安卓设备上运行它时,我只能看到一个空白页面,并且控制台中出现以下错误:
polyfills-es2015.5728f680576ca47e99fe.js:1 Failed to load module script: The
server responded with a non-JavaScript MIME type of "". Strict MIME type
checking is enforced for module scripts per
HTML spec.
main-es2015.734c1bff4ed0a6bbbd29.js:1 Failed to load module script: The
server responded with a non-JavaScript MIME type of "". Strict MIME type
checking is enforced for module scripts per HTML spec.
我可以通过编辑 Angular 创建的
dist/<project>/index.html
文件来解决这个问题。Angular 不再在创建的 <script>
标签中包含 type="text/javascript"
参数,而是如下所示:<script src="runtime-es2015.858f8dd898b75fe86926.js" type="module"></script>
<script src="polyfills-es2015.5728f680576ca47e99fe.js" type="module"></script>
<script src="runtime-es5.741402d1d47331ce975c.js" nomodule></script>
<script src="polyfills-es5.7f43b971448d2fb49202.js" nomodule></script>
<script src="main-es2015.734c1bff4ed0a6bbbd29.js" type="module"></script>
<script src="main-es5.43ecaae92d6e77bfb1c5.js" nomodule></script>
如果我将其更改为type="text/javascript"
,该应用程序可以在我的设备上正确运行。
我该如何告诉Cordova在提供javascript文件时包含正确的MIME类型头?