webpack.config.prod.js 1.86 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');

15
16
var relative = process.argv[2] === 'local' ? '.' : '../..';

Dan Abramov's avatar
Dan Abramov committed
17
18
19
20
module.exports = {
  devtool: 'source-map',
  entry: './src/index.js',
  output: {
21
    path: path.resolve(__dirname, relative, 'build'),
Dan Abramov's avatar
Dan Abramov committed
22
23
24
25
26
27
    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
28
29
30
31
    preLoaders: [
      {
        test: /\.js$/,
        loader: 'eslint-loader',
32
        include: path.resolve(__dirname, relative, 'src')
Dan Abramov's avatar
Dan Abramov committed
33
34
      }
    ],
Dan Abramov's avatar
Dan Abramov committed
35
    loaders: [
Dan Abramov's avatar
Dan Abramov committed
36
37
      {
        test: /\.js$/,
38
        include: path.resolve(__dirname, relative, 'src'),
Dan Abramov's avatar
Dan Abramov committed
39
40
        loader: 'babel'
      },
Dan Abramov's avatar
Dan Abramov committed
41
42
      {
        test: /\.css$/,
43
        include: path.resolve(__dirname, relative, 'src'),
Dan Abramov's avatar
Dan Abramov committed
44
45
46
        loader: 'style!css!postcss'
      },
      {
Dan Abramov's avatar
Dan Abramov committed
47
48
49
50
51
52
53
54
55
56
        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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
      }
    ]
  },
  postcss: function () {
    return [ autoprefixer ];
  },
  plugins: [
    // TODO: infer from package.json?
    new HtmlWebpackPlugin({ title: 'My React Project' }),
    new webpack.DefinePlugin({ 'process.env.NODE_ENV': '"production"' }),
    new webpack.optimize.OccurrenceOrderPlugin(),
    new webpack.optimize.UglifyJsPlugin({ compressor: { warnings: false } })
  ]
};