webpack.config.prod.js 2.85 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
var isInNodeModules = 'node_modules' ===
16
17
  path.basename(path.resolve(path.join(__dirname, '..', '..')));
var relative = isInNodeModules ? '../../..' : '..';
18

Dan Abramov's avatar
Dan Abramov committed
19
module.exports = {
Dan Abramov's avatar
Dan Abramov committed
20
  bail: true,
Dan Abramov's avatar
Dan Abramov committed
21
22
23
  devtool: 'source-map',
  entry: './src/index.js',
  output: {
24
    path: path.resolve(__dirname, relative, 'build'),
Dan Abramov's avatar
Dan Abramov committed
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: '/'
  },
30
31
32
33
  resolveLoader: {
    root: path.join(__dirname, '..', 'node_modules'),
    moduleTemplates: ['*-loader']
  },
Dan Abramov's avatar
Dan Abramov committed
34
  module: {
Dan Abramov's avatar
Dan Abramov committed
35
36
37
    preLoaders: [
      {
        test: /\.js$/,
38
        loader: 'eslint',
39
        include: path.resolve(__dirname, relative, 'src')
Dan Abramov's avatar
Dan Abramov committed
40
41
      }
    ],
Dan Abramov's avatar
Dan Abramov committed
42
    loaders: [
Dan Abramov's avatar
Dan Abramov committed
43
44
      {
        test: /\.js$/,
45
        include: path.resolve(__dirname, relative, 'src'),
46
        loader: 'babel',
47
        query: require('./babel.prod')
Dan Abramov's avatar
Dan Abramov committed
48
      },
Dan Abramov's avatar
Dan Abramov committed
49
50
      {
        test: /\.css$/,
51
        include: path.resolve(__dirname, relative, 'src'),
Dan Abramov's avatar
Dan Abramov committed
52
53
54
        loader: 'style!css!postcss'
      },
      {
Dan Abramov's avatar
Dan Abramov committed
55
56
57
58
59
60
61
62
63
64
        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
65
66
67
      }
    ]
  },
68
  eslint: {
69
70
71
72
    // TODO: consider separate config for production,
    // e.g. to enable no-console and no-debugger only in prod.
    configFile: path.join(__dirname, 'eslint.js'),
    useEslintrc: false
73
74
75
  },
  postcss: function() {
    return [autoprefixer];
Dan Abramov's avatar
Dan Abramov committed
76
77
  },
  plugins: [
Max's avatar
Max committed
78
79
    new HtmlWebpackPlugin({
      inject: true,
Max's avatar
Max committed
80
      template: path.resolve(__dirname, relative, 'index.html'),
Dan Abramov's avatar
Dan Abramov committed
81
82
83
84
85
86
87
88
89
90
91
92
      minify: {
        removeComments: true,
        collapseWhitespace: true,
        removeRedundantAttributes: true,
        useShortDoctype: true,
        removeEmptyAttributes: true,
        removeStyleLinkTypeAttributes: true,
        keepClosingSlash: true,
        minifyJS: true,
        minifyCSS: true,
        minifyURLs: true
      }
Max's avatar
Max committed
93
    }),
Dan Abramov's avatar
Dan Abramov committed
94
95
    new webpack.DefinePlugin({ 'process.env.NODE_ENV': '"production"' }),
    new webpack.optimize.OccurrenceOrderPlugin(),
96
97
98
99
100
101
102
103
104
105
106
107
108
    new webpack.optimize.UglifyJsPlugin({
      compressor: {
        screw_ie8: true,
        warnings: false
      },
      mangle: {
        screw_ie8: true
      },
      output: {
        comments: false,
        screw_ie8: true
      }
    })
Dan Abramov's avatar
Dan Abramov committed
109
110
  ]
};