text: const webpack = require('webpack')
  const ManifestPlugin = require('webpack-manifest-plugin')
  
  const DEBUG = process.env.NODE_ENV !== 'production'
  
  const plugins = [
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': `"${process.env.NODE_ENV}"`
    })
  ]
  const assetsDir = process.env.ASSETS_DIR
  const assetMapFile = process.env.ASSETS_MAP_FILE
  const outputFile = DEBUG ? '[name].js' : '[name].[chunkhash].js'
  
  if (!DEBUG) {
    plugins.push(new ManifestPlugin({
      fileName: assetMapFile
    }))
    plugins.push(new webpack.optimize.UglifyJsPlugin({ minimize: true }))
  }
  
  const config = {
    entry: {
      bundle: ['babel-polyfill', './src/client/index.jsx']
    },
    module: {
      rules: [
        { test: /\.json$/, loader: 'json-loader' },
        { test: /\.css$/, loader: 'style-loader!css' },
        {
          test: /\.jsx?$/,
          loader: 'babel-loader',
          exclude: /(node_modules|bower_components)/,
          query: {
            cacheDirectory: DEBUG
          }
        }
      ]
    },
    node: {
      fs: 'empty'
    },
    resolve: {
      extensions: ['.js', '.jsx']
    },
    plugins,
    output: {
      filename: outputFile,
      path: DEBUG ? '/' : assetsDir,
      publicPath: '/assets/'
    }
  }
  
  if (DEBUG) {
    config.devtool = '#inline-source-map'
  } else if (process.env.NODE_ENV === 'production') {
    config.devtool = 'source-map'
  }
  
  module.exports = config
  