4

WEBPACK @ 2.2 WEBPACK-MERGE @ 2.4

I am using webpack merge to do a smart dev or production config.

My start script looks like

}
"scripts": {
  "start": "webpack --env=production & node start.js",
  "dev": "webpack-dev-server --env=dev",
},

and my webpack-config looks like this:

const webpack = require('webpack')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const CompressionPlugin = require('compression-webpack-plugin')
const webpackMerge = require('webpack-merge')

const baseConfig = function(env) {
  return {
    output: {
      path: '/public/',
      filename: 'index.js',
      publicPath: '/public/',
    },
    module: {
      rules: [
        {
          test: /\.js$/,
          exclude: /node_modules/,
          use: ['babel-loader'],
        },
        {
          test: /\.css$/,
          loader: ExtractTextPlugin.extract({
            fallbackLoader: "style-loader",
            loader: "css-loader",
            publicPath: "/public/",
          }),
        },
      ],
    },
    resolve: {
      extensions: ['.js', '.css'],
    },
    plugins: [
      new webpack.DefinePlugin({
        'process.env': { NODE_ENV: JSON.stringify(env) },
      }),
      new ExtractTextPlugin({
        filename: "bundle.css",
        disable: false,
        allChunks: true,
      }),
    ],
  }
}

module.exports = function(env) {
  return webpackMerge(baseConfig(env), env === 'dev' ? {
    devtool: 'cheap-module-source-map',
    entry: [
      'react-hot-loader/patch',
      'webpack-dev-server/client?http://localhost:8080',
      'webpack/hot/only-dev-server',
      './app/index.js',
    ],
    devServer: {
      hot: true,
      publicPath: '/public/',
      proxy: {
        "/api/**": "http://localhost:3333",
        "/auth/**": "http://localhost:3333",
      },
    },
    plugins: [
      new webpack.HotModuleReplacementPlugin(),
      new webpack.NamedModulesPlugin(),
    ],
  } : {
    devtool: 'inline-source-map',
    entry: [
      './app/index.js',
    ],
    plugins: [
      new webpack.optimize.UglifyJsPlugin({
        comments: false,
      }),
      new webpack.LoaderOptionsPlugin({
        minimize: true,
      }),
      new webpack.optimize.AggressiveMergingPlugin(),
      new CompressionPlugin({
        asset: "[path].gz[query]",
        algorithm: "gzip",
        test: /\.js$|\.css$|\.html$/,
        threshold: 10240,
        minRatio: 0.8,
      }),
    ],
  })
}

Webpack successfully compiles locally but when I attempt to deploy it to heroku, the output in papertrail is as seen below:

> webpack --env=production & node start.js 
Config did not export an object. 

Any ideas?

Austin Witherow
  • 456
  • 2
  • 4
  • 19

1 Answers1

3

I had the same issue, I forgot to install webpack dev server:
npm install --save-dev webpack-dev-server

Hope it helps!

vlio20
  • 8,955
  • 18
  • 95
  • 180
  • 1
    I am experiencing exactly the same error but I have already installed webpack-dev-server. The problem arose when I am trying to create multiple configurations for dev and production – trevorgk May 22 '17 at 03:31