我只是尝试使用 Parcel build /src/index.html 生成构建, 我能够构建应用程序,但是当我尝试从浏览器打开构建时,它说构建后无法从index.html访问index.js。
<body>
<div id="root"></div>
<script src="index.js" type="module"></script>
</body>
无论如何,我在本地运行该项目没有任何问题。 请看下面的图片以了解我的担忧。 谢谢。
您需要从网络服务器提供
dist
目录。
F.I.从您的终端:
cd dist
npx serve
如果是 npm 项目,可以在 package.json 的脚本中添加此内容
"build": "parcel build index.html",
这将为您提供生产版本或简单地运行
npx parcel build index.html
并在本地运行应用程序
cd dist
npx serve