webpack.config.prod.js 3.71 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
var path = require('path');
var autoprefixer = require('autoprefixer');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
14
var ExtractTextPlugin = require('extract-text-webpack-plugin');
Dan Abramov's avatar
Dan Abramov committed
15

16
17
// TODO: hide this behind a flag and eliminate dead code on eject.
// This shouldn't be exposed to the user.
Dan Abramov's avatar
Dan Abramov committed
18
var isInNodeModules = 'node_modules' ===
19
  path.basename(path.resolve(path.join(__dirname, '..', '..')));
20
21
22
23
24
25
26
var relativePath = isInNodeModules ? '../../..' : '..';
if (process.argv[2] === '--debug-template') {
  relativePath = '../template';
}
var srcPath = path.resolve(__dirname, relativePath, 'src');
var nodeModulesPath = path.join(__dirname, '..', 'node_modules');
var indexHtmlPath = path.resolve(__dirname, relativePath, 'index.html');
Dan Abramov's avatar
Dan Abramov committed
27
var faviconPath = path.resolve(__dirname, relativePath, 'favicon.ico');
28
var buildPath = path.join(__dirname, isInNodeModules ? '../../..' : '..', 'build');
29

Dan Abramov's avatar
Dan Abramov committed
30
module.exports = {
Dan Abramov's avatar
Dan Abramov committed
31
  bail: true,
Dan Abramov's avatar
Dan Abramov committed
32
  devtool: 'source-map',
33
  entry: path.join(srcPath, 'index'),
Dan Abramov's avatar
Dan Abramov committed
34
  output: {
35
    path: buildPath,
36
37
    filename: '[name].[chunkhash].js',
    chunkFilename: '[name].[chunkhash].chunk.js',
Dan Abramov's avatar
Dan Abramov committed
38
39
40
41
    // TODO: this wouldn't work for e.g. GH Pages.
    // Good news: we can infer it from package.json :-)
    publicPath: '/'
  },
42
43
44
  resolve: {
    extensions: ['', '.js'],
  },
45
  resolveLoader: {
46
    root: nodeModulesPath,
47
48
    moduleTemplates: ['*-loader']
  },
Dan Abramov's avatar
Dan Abramov committed
49
  module: {
Dan Abramov's avatar
Dan Abramov committed
50
51
52
    preLoaders: [
      {
        test: /\.js$/,
53
        loader: 'eslint',
54
        include: srcPath
Dan Abramov's avatar
Dan Abramov committed
55
56
      }
    ],
Dan Abramov's avatar
Dan Abramov committed
57
    loaders: [
Dan Abramov's avatar
Dan Abramov committed
58
59
      {
        test: /\.js$/,
60
        include: srcPath,
61
        loader: 'babel',
62
        query: require('./babel.prod')
Dan Abramov's avatar
Dan Abramov committed
63
      },
Dan Abramov's avatar
Dan Abramov committed
64
65
      {
        test: /\.css$/,
66
        include: [srcPath, nodeModulesPath],
67
68
69
70
        // Disable autoprefixer in css-loader itself:
        // https://github.com/webpack/css-loader/issues/281
        // We already have it thanks to postcss.
        loader: ExtractTextPlugin.extract('style', 'css?-autoprefixer!postcss')
Dan Abramov's avatar
Dan Abramov committed
71
72
      },
      {
Dan Abramov's avatar
Dan Abramov committed
73
74
75
76
77
78
79
80
81
82
        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
83
84
85
      }
    ]
  },
86
  eslint: {
87
88
89
90
    // 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
91
92
93
  },
  postcss: function() {
    return [autoprefixer];
Dan Abramov's avatar
Dan Abramov committed
94
95
  },
  plugins: [
Max's avatar
Max committed
96
97
    new HtmlWebpackPlugin({
      inject: true,
98
      template: indexHtmlPath,
Dan Abramov's avatar
Dan Abramov committed
99
      favicon: faviconPath,
Dan Abramov's avatar
Dan Abramov committed
100
101
102
103
104
105
106
107
108
109
110
111
      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
112
    }),
Dan Abramov's avatar
Dan Abramov committed
113
114
    new webpack.DefinePlugin({ 'process.env.NODE_ENV': '"production"' }),
    new webpack.optimize.OccurrenceOrderPlugin(),
115
    new webpack.optimize.DedupePlugin(),
116
117
118
119
120
121
122
123
124
125
126
127
    new webpack.optimize.UglifyJsPlugin({
      compressor: {
        screw_ie8: true,
        warnings: false
      },
      mangle: {
        screw_ie8: true
      },
      output: {
        comments: false,
        screw_ie8: true
      }
128
129
    }),
    new ExtractTextPlugin('[name].[contenthash].css')
Dan Abramov's avatar
Dan Abramov committed
130
131
  ]
};