Webpack默认为/ public目录

时间:2016-11-17 01:18:58

标签: reactjs webpack webpack-dev-server

我有一个React应用程序,我正在移植到Webpack,我可以使用webpack-dev-server成功启动它。

不幸的是,我必须导航到公共目录才能加载应用程序:

localhost:10000/public/

...干扰React路由器。它可以安装到/取而代之吗?即:

localhost:10000/

输出中的publicPath指令似乎不会影响这一点。

// webpack.config.js
module.exports = {
  devServer: {
    inline: true,
    port: 10000 // Defaults to 8080
  },
  entry: {
    app: ['./src/app.jsx']
  },
  devtool: 'source-map',
  resolve: {
    extensions: ['', '.js', '.jsx']
  },
  output: {
    path: path.resolve(__dirname, "public/scripts"),
    publicPath: '/scripts/',
    filename: 'bundle.js'
  },
  module: {
    loaders: [
      {
        test: /\.jsx?$/,
        loader: 'babel-loader',
        exclude: /node_modules/,
        query: {
          presets: [
            "es2015",
            "stage-0",
            "react"
          ],
          plugins: [
            "transform-flow-strip-types"
          ]
        }
      }
    ]
  }
};

1 个答案:

答案 0 :(得分:1)

尝试将contentBase设置为公用文件夹

https://webpack.github.io/docs/configuration.html#devserver