[英]render bundle.js file on page using html.js
我正在为我的反应项目使用 webpack 来生成 index.bundle.js 文件。
这是我的 webpack.config.js...代码
const path = require('path');
module.exports = {
output: {
path: path.join(__dirname, '/dist'),
filename: 'index.bundle.js',
},
// entry:{
// path: path.join(__dirname, '/dist')
// },
devServer: {
port: 3000,
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.(sa|sc|c)ss$/, // styles files
use: ["style-loader", "css-loader", "sass-loader"],
},
{
test: /\.(png|woff|woff2|eot|ttf|svg|jpeg|webp)$/, // to import images and fonts
loader: "url-loader",
options: { limit: false },
}
]
},
};
这是我的 index.html 文件... index.html file is inside public folder
<!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>
<div id="root"></div>
<script src="/index.bundle.js"></script>
</body>
</html>
我的 index.bundle.js 文件在 dist 文件中,名称为index.bundle.js
。
我想在这里检查我的index.bundle.js
是否编译成功,我正在尝试在 index.html 中运行index.bundle.js
。 所以我可以使用index.bundle.js
查看我的反应项目。 所以这就是我在做什么。
i am using
在默认浏览器中打开extension to run my html code on browser. I am not sure i am doing right step,, If not How can i run html code
extension to run my html code on browser. I am not sure i am doing right step,, If not How can i run html code
第二件事
如果在 index.html 内,我将脚本 src 路径更改为
<script src="../dist/index.bundle.js"></script>
我收到这个错误..
index.bundle.js:2 Uncaught Error: ES Modules may not assign module.exports or exports.*, Use ESM export syntax, instead: 2752
at Object.set [as exports] (index.bundle.js:2:1234650)
at 2752 (index.bundle.js:2:168796)
at a (index.bundle.js:2:1233913)
at index.bundle.js:2:1237036
at index.bundle.js:2:1237044
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.