美好的一天,伙计们!我在网上寻找解决方案,但找不到解决方案,所以我向您寻求帮助。当我完整描述情况时,请耐心等待。
我是一个初学者,在开发引导网络项目时遇到了包裹问题。
First, it throws an error for using index.js which doesn't make any sense. As per the bootstrap, doc. folder structure suppose to be
project-name/
├── build/
├── node_modules/
│ └── bootstrap/
│ └── popper.js/
├── scss/
│ └── custom.scss
├── src/
│ └── index.html
│ └── index.js
└── package.json
我正在关注引导文档。链接:https ://getbootstrap.com/docs/5.0/getting-started/parcel/
项目使用的包:
包裹打包机,
popperjs 和
引导程序
使用简单的 HTML 重新创建问题
索引.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>HELLOW WORLD</h1>
<script type="module" src="index.js"></script>
</body>
</html>
index.js
import * as bootstrap from 'bootstrap';
alert('JAVA is LOADED');
console.log('Java is loaded another example');
自定义.scss
@import "../node_modules/bootstrap/scss/bootstrap";
包.json
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "parcel ./src/index.html",
"prebuild": "npx rimraf build",
"build": "parcel build --public-url ./ ./src/index.html --dist-dir build"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@popperjs/core": "^2.9.2",
"bootstrap": "^5.0.2"
}
}
错误信息:
@parcel/namer-default: Target "main" declares an output file path of "index.js" which does not match the compiled bundle type "html".
/Users/abc/Visual_Code/test/package.json:5:11
4 | "description": "",
> 5 | "main": "index.js",
> | ^^^^^^^^^^^^^^^^^^ Did you mean "index.html"?
6 | "scripts": {
7 | "dev": "parcel ./src/index.html",
Try changing the file extension of "main" in package.json.
互联网上的其他帖子建议将**"main":**
value替换为,"../dist/index.js,"
但它也不起作用。当我尝试消除整"main":
行时,构建了 webapp,但没有加载 java。如果我这样做npm run dev
,webapp 会执行 javascript(我在 dev 模式下维护“main”:“index.js”),我可以在控制台中看到警报消息和日志消息,但它在构建应用程序时不起作用。当我在包裹中开发我的 web 应用程序时走得太远,我对此时可以做什么完全一无所知。
我将衷心感谢您的帮助!