// package.json
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "webpack-dev-server"
},
"devDependencies": {
"webpack": "^2.6.1",
"webpack-dev-server": "^2.4.5"
}
// webpack.config.js
module.exports={
entry:'./app/index.js',
output:{
path: __dirname + "/public",
filename: "bundle.js"
}
}
// index.html
<body>
<div>
测试
</div>
<script src="./public/bundle.js">
</script>
</body>
//index.js
console.log(13456);
document.write('helloworld1212')
下面就是npm start
启动后CLI显示success,但是chrome的控制台报的错误GET http://localhost:8080/public/bundle.js 404 (Not Found)
已经纠结一天,恳请大神帮助,或者提供自己的建议
当我尝试把bundle.js外面的文件夹public拿掉即更改webpack.config.js
和index.heml
文件
// webpack.config.js
module.exports={
entry:'./app/index.js',
output:{
//path: __dirname + "/public",
filename: "bundle.js"
}
}
// index.html
<body>
<div>
测试
</div>
<script src="./bundle.js">
</script>
</body>
这种情况下,一切运行正常。
说明浏览器没有检测到
/public/bundle.js
,你执行webpack
进行打包吗?执行过了
webpack
才会生成bundle.js
我本地试过了也是404