1

I've just gotten started with Webpack, so I've got just enough knowledge to be dangerous and I'm sure I've made quite a mess of my config file. But it's quite closely modeled after the surviveJS example, which is running on my machine without problem. However, when I load my app I get a whole series of messages in the console about some websocket handshake failing.

Why?

and everything loads twice. And whenever I update a file I get more errors in addition to a repetition of all of the errors above.

More errors :(

Any idea why it's so angry at me?

Here's my webpack config (the build works just fine):

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
        }
      })
    ]
  });
}
aname
  • 35
  • 6

0 Answers0