我终于让他的dev服务器运行了,我在屏幕上得到了一些东西。我为NPM设置了一个“启动”脚本,如下所示:
"start": "webpack-dev-server --content-base app"
我收到一个错误:
http://localhost:8080/bundle.js Failed to load resource: the server responded with a status of 404 (Not Found)
我的文件夹设置如下:
appDir
->app
->node_modules
webpack.config.js
package.json
我的webpack.config.js:
module.exports = {
context: __dirname + '/app',
entry: './index.js',
output: {
path: __dirname + '/app',
filename: './bundle.js'
}
}
你能说出什么问题吗?
bundle.js位于/app
目录中。输出中的path
选项指定文件的绝对路径。
你也不需要文件名中的./
。它将相对于output.path
得到解决,但它令人困惑,可能导致了你的问题。
问题主要是在index.html中指向bundle js。找不到webpack bundle.js的原因是因为您需要在index.html中指定绝对路径。假设您的bundle.js和index.html是在dist文件夹下生成的,那么它应该是类似下面的内容。
<script src="/bundle.js"></script>