Webpack Dev Server /热模块替换页面加载Websocket错误

时间:2016-05-20 23:12:36

标签: webpack webpack-dev-server hot-module-replacement survivejs

我刚刚开始使用Webpack,所以我已经掌握了足够的知识,并且我确信我的配置文件已经搞得一团糟了。但它在surviveJS example之后非常接近建模,它在我的机器上运行没有问题。但是,当我加载我的应用程序时,我在控制台中收到一系列关于某些websocket握手失败的消息。

Why?

并且一切都加载了两次。每当我更新文件时,除了重复上述所有错误之外,我还会遇到更多错误。

More errors :(

知道为什么它对我如此生气?

这是我的webpack配置(构建工作正常):

require('dotenv').config();

const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanPlugin = require('clean-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');

const pkg = require('./package.json');

const TARGET = process.env.npm_lifecycle_event;
const PATHS = {
    app: path.join(__dirname, 'src/client'),
    style: path.join(__dirname, 'src/client/components/main.scss'),
    build: path.join(__dirname, 'dist/client')
};
process.env.BABEL_ENV = TARGET;

const common = {
  entry: {
    app: PATHS.app,
    style: PATHS.style
  },
  resolve: {
    extensions: ['', '.js', '.jsx']
  },
  output: {
    path: PATHS.build,
    chunkFilename: '[chunkhash].js'
  },
  module: {
    loaders: [
      {
        test: /\.js(x?)$/,
        loaders: ['babel?cacheDirectory'],
        include: PATHS.app
      }
    ]
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: 'node_modules/html-webpack-template/index.ejs',
      title: 'Score Fluent',
      appMountId: 'app',
      inject: false
    })
  ]
}

// Add dev server config
if (TARGET === 'start' || !TARGET) {
  module.exports = merge(common, {
    output: {
      filename: '[name].js',
    },
    module: {
      loaders: [
        {
          test: /\.s(c|a)ss$/,
          loaders: ['style', 'css', 'sass'],
          include: PATHS.app
        }
      ]
    },
    devServer: {
      historyApiFallback: true,
      hot: true,
      inline: true,
      progress: true,
      stats: 'errors-only',
      host: process.env.HOST,
      port: process.env.PORT
    },
    devtool: 'eval-source-map',
    plugins: [
      new webpack.HotModuleReplacementPlugin()
    ]
  });
}

// Just build it
if (TARGET === 'build' || TARGET === 'stats') {
  module.exports = merge(common, {
    entry: {
      vendor: Object.keys(pkg.dependencies).filter(function(v) {
        return v !== 'alt-utils'
      })
    },
    output: {
      filename: '[name].[chunkhash].js'
    },
    module: {
      loaders: [
        {
          test: /\.s(c|a)ss$/,
          loader: ExtractTextPlugin.extract('style', 'css', 'sass'),
          include: PATHS.app
        }
      ]
    },
    plugins: [
      new webpack.DefinePlugin({
        'process.env.NODE_ENV': '"production"'
      }),
      new CleanPlugin([PATHS.build]),
      new webpack.optimize.DedupePlugin(),
      new webpack.optimize.CommonsChunkPlugin({
        names: ['vendor', 'manifest']
      }),
      new ExtractTextPlugin('[name].[chunkhash].css'),
      new webpack.optimize.UglifyJsPlugin({
        compress: {
          warnings: false
        }
      })
    ]
  });
}

0 个答案:

没有答案