Webpack:找不到bundle.js

问题描述 投票:5回答:2

我终于让他的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'
    }
}

你能说出什么问题吗?

javascript node.js webpack
2个回答
8
投票

bundle.js位于/app目录中。输出中的path选项指定文件的绝对路径。

你也不需要文件名中的./。它将相对于output.path得到解决,但它令人困惑,可能导致了你的问题。


0
投票

问题主要是在index.html中指向bundle js。找不到webpack bundle.js的原因是因为您需要在index.html中指定绝对路径。假设您的bundle.js和index.html是在dist文件夹下生成的,那么它应该是类似下面的内容。

<script src="/bundle.js"></script>
© www.soinside.com 2019 - 2024. All rights reserved.