webpack dev服务器无法正常工作

时间:2017-04-12 11:13:34

标签: reactjs webpack webpack-dev-server

我无法让webpack dev服务器工作。我的应用程序结构如下。在 src 目录中,我有两个目录,服务器客户端。我通过在localhost:3000上运行来启动服务器,并通过运行webpack来启动客户端,该文件夹在客户端目录中生成 dist 文件夹。 我该如何解决这个问题?

文件结构

enter image description here

服务器/ index.js

app.set('views', path.join(__dirname, 'views'))
app.set('view engine', 'ejs')
app.use(Express.static(path.join(__dirname, '../', 'client')))
...
app.listen(3000, function () {
  console.log('Express server is up on port 3000')
})

服务器/视图/ index.ejs

<body>
  <h1>EJS Static</h1>
  <div id="app"></div>
  <script src="dist/bundle.js"></script>
</body>

webpack.config.babel.js

import path from 'path'
const publicPath = path.resolve(__dirname, './src/client')

context: publicPath,
  entry: {
    bundle: [
      'webpack-dev-server/client?http://localhost:8080',
      'webpack/hot/only-dev-server',
      'script-loader!jquery/dist/jquery.min.js',
      'script-loader!tether/dist/js/tether.min.js',
      'script-loader!bootstrap/dist/js/bootstrap.min.js',
      './app.js'
    ]
  },
  output: {
    path: path.join(publicPath, 'dist'),
    filename: '[name].js',
    publicPath: '/dist/'
  },

   plugins: [
    ...
    new webpack.HotModuleReplacementPlugin()
  ],
  devServer: {
    contentBase: path.join(publicPath, '/dist')
  }

的package.json

"scripts": {
...
"serve": "webpack-dev-server",
}

0 个答案:

没有答案