webpack-dev-server启动后找不到 bundle.js

webpack.config.js 配置:

const path = require('path');


const paths = {
  appSrc: path.resolve(__dirname, 'src'),
  buildPath: path.resolve(__dirname, 'dist'),
  nodeModules: path.resolve(__dirname, 'node_modules'),
}


module.exports = (env, argv) => {
  return {
    target: 'web',
    entry: path.resolve(__dirname, 'src/index.js'),
    output: {
      path: paths.buildPath,
      filename: 'bundle .js',
      publicPath: path.resolve(__dirname, 'public')
    },
    module: {
      rules: [{
          test: /\.js$/,
          exclude: paths.nodeModules,
          loaders: ['babel-loader']
        },
        {
          test: /\.css$/,
          loaders: ['style-loader', 'css-loader']
        },
        {
          test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/, /\.svg$/],
          exclude: paths.appNodeModules,
          use: [{
            loader: 'url-loader',
            options: {
              limit: 1024 //小于1024kb的图片使用base64
            }
          }]
        }
      ]
    },
    devServer: {
      publicPath: '/',
      //之前 index.html 在 public 下,后来放到根路径下都不行
      // contentBase: path.resolve(__dirname, 'public'),
      hot: true,
      hotOnly: true,
      inline: true,
      port: 3000,
      open: true,
      //使用代理,处理所有包含 /api 的请求 
      proxy: {
        '/api': {
          target: 'http://localhost:8001',
          secure: false
        }
      }
    }
  }
}
//index.html 
<script type="text/javascript" src="bundle.js"></script>

这里试了 /dist/bundle.js 也不行.
工程结构:
clipboard.png

报错.

clipboard.png

阅读 2.7k
1 个回答

路径不对吧 public/dist/bundle.js

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题