1

我在我们的 Rails 应用程序中使用 React 和 webpack 的 react-hot-loader 插件设置了 Webpack。它正在成功运行并构建bundle.js我期望的文件,但它也在每次热更新时给我这样的文件0.bfeb31eda5c7e8da9473.hot-update.js。我正在使用的一个插件的作者WriteFileWebpackPlugin说,我可以在test属性中告诉它不要监视.hot其中的文件,但我不知道如何让它工作。

这是我的 webpack.config.js

var webpack = require('webpack')
var path = require('path')
var WriteFilePlugin = require('write-file-webpack-plugin')

module.exports = {
  // watchOptions: {
  //   poll: true
  // },
  context: __dirname + '/app/assets/javascripts',
  entry: {
    App: [
      'webpack-dev-server/client?http://localhost:8080/',
      'webpack/hot/only-dev-server',
      path.resolve(__dirname, 'app/assets/source/index.js')
    ]
  },
  output: {
    path: path.resolve(__dirname, 'app/assets/javascripts'),
    publicPath: 'http://localhost:8080/',
    filename: 'bundle.js'
  },
  module: {
    loaders: [
      { test: /\.js$/,
        loaders: ["react-hot", "babel"],
        include: path.resolve(__dirname, 'app/assets/source')
      }
    ]
  },
  devtool: 'inline-source-map',
  devServer: {
    outputPath: path.resolve(__dirname, 'app/assets/javascripts')
  },
  plugins: [
    new WriteFilePlugin({test: /^.*[^\.].*\.js$/}),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoErrorsPlugin()
  ]
}

有没有其他人遇到过这个?理想情况下,我想弄清楚test如果可能的话,是否可以在没有该属性的情况下解决此问题,但即使只是弄清楚这一点也会有所帮助。

4

1 回答 1

1

好的,我没有使用过那个插件,但是你说你需要更新以下内容:

老的

  module: {
    loaders: [
      { test: /\.js$/,
        loaders: ["react-hot", "babel"],
        include: path.resolve(__dirname, 'app/assets/source')
      }
    ]
  },

新的

module: {
    loaders: [
      { test: /^((?!(.hot-update)).)*\.js$/,
        loaders: ["react-hot", "babel"],
        include: path.resolve(__dirname, 'app/assets/source')
      }
    ]
  },
于 2016-09-15T10:24:30.137 回答