Skip to content
Snippets Groups Projects
webpack.config.prod.js 1.08 KiB
Newer Older
Cliff Li's avatar
Cliff Li committed
import { optimize } from 'webpack';
import CompressionPlugin from 'compression-webpack-plugin';

const config = {
  context: `${__dirname}/src`, // `__dirname` is root of project and `src` is source

  entry: './index.js',

  output: {
    path: `${__dirname}/dist`, // `dist` is the destination
    filename: 'bundle.js',
  },

  // To run development server
  devServer: {
    contentBase: __dirname,
    publicPath: '/dist',
    compress: true,
    port: 9000,
    hot: true,
    index: 'index.html',
  },

  module: {
    rules: [
      {
        test: /\.js$/, // Check for all js files
        exclude: /node_modules/,
        use: [{
          loader: 'babel-loader',
          options: { presets: ['env'] },
        }],
      },
scmoritz's avatar
scmoritz committed
    ],
Cliff Li's avatar
Cliff Li committed
    new optimize.UglifyJsPlugin(),
    new optimize.AggressiveMergingPlugin(),
    new CompressionPlugin({
      asset: '[path].gz[query]',
      algorithm: 'gzip',
      test: /\.js$|\.css$|\.html$/,
      threshold: 10240,
      minRatio: 0.8,
    }),
  ],

  devtool: '', // No source map for production build
scmoritz's avatar
scmoritz committed
};

Cliff Li's avatar
Cliff Li committed
export default config;