webpack.config.prod.js 2.27 KB
Newer Older
Christopher Chedeau's avatar
Christopher Chedeau committed
1
2
3
4
5
6
7
8
9
/**
 * Copyright (c) 2015-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 */

Dan Abramov's avatar
Dan Abramov committed
10
11
12
13
14
var path = require('path');
var autoprefixer = require('autoprefixer');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');

Dan Abramov's avatar
Dan Abramov committed
15
16
17
var isInNodeModules = 'node_modules' ===
  path.basename(path.resolve(path.join(__dirname, '..')));
var relative = isInNodeModules ? '../..' : '.';
18

Dan Abramov's avatar
Dan Abramov committed
19
20
21
22
module.exports = {
  devtool: 'source-map',
  entry: './src/index.js',
  output: {
23
    path: path.resolve(__dirname, relative, 'build'),
Dan Abramov's avatar
Dan Abramov committed
24
25
26
27
28
29
    filename: '[name].[hash].js',
    // TODO: this wouldn't work for e.g. GH Pages.
    // Good news: we can infer it from package.json :-)
    publicPath: '/'
  },
  module: {
Dan Abramov's avatar
Dan Abramov committed
30
31
32
    preLoaders: [
      {
        test: /\.js$/,
33
        loader: 'eslint',
34
        include: path.resolve(__dirname, relative, 'src')
Dan Abramov's avatar
Dan Abramov committed
35
36
      }
    ],
Dan Abramov's avatar
Dan Abramov committed
37
    loaders: [
Dan Abramov's avatar
Dan Abramov committed
38
39
      {
        test: /\.js$/,
40
        include: path.resolve(__dirname, relative, 'src'),
41
42
43
44
45
46
47
48
        loader: 'babel',
        query: {
          presets: ['es2015', 'es2016', 'react'],
          plugins: [
            'transform-object-rest-spread',
            'transform-react-constant-elements'
          ]
        }
Dan Abramov's avatar
Dan Abramov committed
49
      },
Dan Abramov's avatar
Dan Abramov committed
50
51
      {
        test: /\.css$/,
52
        include: path.resolve(__dirname, relative, 'src'),
Dan Abramov's avatar
Dan Abramov committed
53
54
55
        loader: 'style!css!postcss'
      },
      {
Dan Abramov's avatar
Dan Abramov committed
56
57
58
59
60
61
62
63
64
65
        test: /\.json$/,
        loader: 'json'
      },
      {
        test: /\.(jpg|png|gif|eot|svg|ttf|woff|woff2)$/,
        loader: 'file',
      },
      {
        test: /\.(mp4|webm)$/,
        loader: 'url?limit=10000'
Dan Abramov's avatar
Dan Abramov committed
66
67
68
      }
    ]
  },
69
70
71
72
73
  eslint: {
    configFile: path.join(__dirname, '.eslintrc')
  },
  postcss: function() {
    return [autoprefixer];
Dan Abramov's avatar
Dan Abramov committed
74
75
76
  },
  plugins: [
    // TODO: infer from package.json?
Max's avatar
Max committed
77
78
    new HtmlWebpackPlugin({
      inject: true,
Max's avatar
Max committed
79
      template: path.resolve(__dirname, relative, 'index.html'),
Max's avatar
Max committed
80
    }),
Dan Abramov's avatar
Dan Abramov committed
81
82
83
84
85
    new webpack.DefinePlugin({ 'process.env.NODE_ENV': '"production"' }),
    new webpack.optimize.OccurrenceOrderPlugin(),
    new webpack.optimize.UglifyJsPlugin({ compressor: { warnings: false } })
  ]
};