javascript - Parceljs 没有正确捆绑产品?

标签 javascript parceljs

我正在测试parceljs,并且可以很好地进行开发。我有一个普通的 css 来改变背景颜色,还有一个非常简单的 js 文件只是为了看看它是否工作。

CSS

body {
background-color: lightblue;
}

js

document.getElementById('app').textContent = 'hey'

所以所有这些都在开发模式下工作。但我在/dist/index.html 上尝试了实时服务器,我看到的只是裸露的 html。没有样式,并且脚本不会呈现。我还尝试了“parcel build”命令。和同样的事情。我需要做什么?

package.json

{
  "name": "parceltest1",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "parcel ./src/index.html",
    "build": "parcel build ./src/index.html"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "parcel-bundler": "^1.12.4"
  }
}
Failed to load resource: the server responded with a status of 404 (Not Found)
Refused to apply style from 'http://127.0.0.1:5500/src.e31bb0bc.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled

最佳答案

尝试将“--public-url ./”添加到您的parcel命令中。 更多信息请参见:https://github.com/parcel-bundler/parcel/issues/1865

关于javascript - Parceljs 没有正确捆绑产品?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58673160/

相关文章:

javascript - 无法读取未定义的属性 'score'

php - jquery函数中的变量为null

javascript - ElectronJS 和 React DevTools : "Extension server error: Operation failed: http://localhost:3000/has no execution context", 来源:devtools://

javascript - 如何更改parcel js中的 `sourceMappingURL`

javascript - 配置vscode任务在parcel watch后复制文件

javascript - 包裹JS。使用 --public-url 选项

javascript - 使用 javascript 显示许多相同单词的最简单方法

JavaScript for..in 语句在 IE8 中给出意想不到的结果

angular - 使用 Angular 4+ 版本时,是否有任何专家可以用 Parcel 替换 Webpack?

javascript - 如何在javascript中为已选择的选项点击触发onclick/onchange事件