鍍金池/ 問答/HTML/ webpack-dev-server啟動后找不到 bundle.js

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 也不行.
工程結(jié)構(gòu):
clipboard.png

報錯.

clipboard.png

回答
編輯回答
你的瞳

路徑不對吧 public/dist/bundle.js

2017年2月10日 07:55