webpack.config.prod.js 2.72 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
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
        loader: 'babel',
42
        query: require('./babel.prod')
Dan Abramov's avatar
Dan Abramov committed
43
      },
Dan Abramov's avatar
Dan Abramov committed
44
45
      {
        test: /\.css$/,
46
        include: path.resolve(__dirname, relative, 'src'),
Dan Abramov's avatar
Dan Abramov committed
47
48
49
        loader: 'style!css!postcss'
      },
      {
Dan Abramov's avatar
Dan Abramov committed
50
51
52
53
54
55
56
57
58
59
        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
60
61
62
      }
    ]
  },
63
  eslint: {
64
65
66
67
    // 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
68
69
70
  },
  postcss: function() {
    return [autoprefixer];
Dan Abramov's avatar
Dan Abramov committed
71
72
  },
  plugins: [
Max's avatar
Max committed
73
74
    new HtmlWebpackPlugin({
      inject: true,
Max's avatar
Max committed
75
      template: path.resolve(__dirname, relative, 'index.html'),
Dan Abramov's avatar
Dan Abramov committed
76
77
78
79
80
81
82
83
84
85
86
87
      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
88
    }),
Dan Abramov's avatar
Dan Abramov committed
89
90
    new webpack.DefinePlugin({ 'process.env.NODE_ENV': '"production"' }),
    new webpack.optimize.OccurrenceOrderPlugin(),
91
92
93
94
95
96
97
98
99
100
101
102
103
    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
104
105
  ]
};