webpack.config.prod.js 3.48 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');
15
var url = require('url');
16
var paths = require('./paths');
Dan Abramov's avatar
Dan Abramov committed
17

18
var homepagePath = require(paths.appPackageJson).homepage;
19
var publicPath = homepagePath ? url.parse(homepagePath).pathname : '/';
20
21
22
23
if (!publicPath.endsWith('/')) {
  // Prevents incorrect paths in file-loader
  publicPath += '/';
}
24

Dan Abramov's avatar
Dan Abramov committed
25
module.exports = {
Dan Abramov's avatar
Dan Abramov committed
26
  bail: true,
Dan Abramov's avatar
Dan Abramov committed
27
  devtool: 'source-map',
28
  entry: path.join(paths.appSrc, 'index'),
Dan Abramov's avatar
Dan Abramov committed
29
  output: {
30
    path: paths.appBuild,
31
32
    filename: '[name].[chunkhash:8].js',
    chunkFilename: '[name].[chunkhash:8].chunk.js',
33
    publicPath: publicPath
Dan Abramov's avatar
Dan Abramov committed
34
  },
35
36
37
  resolve: {
    extensions: ['', '.js'],
  },
38
  resolveLoader: {
39
    root: paths.ownNodeModules,
40
41
    moduleTemplates: ['*-loader']
  },
Dan Abramov's avatar
Dan Abramov committed
42
  module: {
Dan Abramov's avatar
Dan Abramov committed
43
44
45
    preLoaders: [
      {
        test: /\.js$/,
46
        loader: 'eslint',
47
        include: paths.appSrc
Dan Abramov's avatar
Dan Abramov committed
48
49
      }
    ],
Dan Abramov's avatar
Dan Abramov committed
50
    loaders: [
Dan Abramov's avatar
Dan Abramov committed
51
52
      {
        test: /\.js$/,
53
        include: paths.appSrc,
54
        loader: 'babel',
55
        query: require('./babel.prod')
Dan Abramov's avatar
Dan Abramov committed
56
      },
Dan Abramov's avatar
Dan Abramov committed
57
58
      {
        test: /\.css$/,
59
        include: [paths.appSrc, paths.appNodeModules],
60
61
62
63
        // 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
64
65
      },
      {
Dan Abramov's avatar
Dan Abramov committed
66
        test: /\.json$/,
67
        include: [paths.appSrc, paths.appNodeModules],
Dan Abramov's avatar
Dan Abramov committed
68
69
70
71
        loader: 'json'
      },
      {
        test: /\.(jpg|png|gif|eot|svg|ttf|woff|woff2)$/,
72
        include: [paths.appSrc, paths.appNodeModules],
Dan Abramov's avatar
Dan Abramov committed
73
        loader: 'file',
74
75
76
        query: {
          name: '[name].[hash:8].[ext]'
        }
Dan Abramov's avatar
Dan Abramov committed
77
78
79
      },
      {
        test: /\.(mp4|webm)$/,
80
        include: [paths.appSrc, paths.appNodeModules],
Dan Abramov's avatar
Dan Abramov committed
81
        loader: 'url?limit=10000'
Dan Abramov's avatar
Dan Abramov committed
82
83
84
      }
    ]
  },
85
  eslint: {
86
87
88
89
    // 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
90
91
92
  },
  postcss: function() {
    return [autoprefixer];
Dan Abramov's avatar
Dan Abramov committed
93
94
  },
  plugins: [
Max's avatar
Max committed
95
96
    new HtmlWebpackPlugin({
      inject: true,
97
98
      template: paths.appHtml,
      favicon: paths.appFavicon,
Dan Abramov's avatar
Dan Abramov committed
99
100
101
102
103
104
105
106
107
108
109
110
      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
111
    }),
Dan Abramov's avatar
Dan Abramov committed
112
113
    new webpack.DefinePlugin({ 'process.env.NODE_ENV': '"production"' }),
    new webpack.optimize.OccurrenceOrderPlugin(),
114
    new webpack.optimize.DedupePlugin(),
115
116
117
118
119
120
121
122
123
124
125
126
    new webpack.optimize.UglifyJsPlugin({
      compressor: {
        screw_ie8: true,
        warnings: false
      },
      mangle: {
        screw_ie8: true
      },
      output: {
        comments: false,
        screw_ie8: true
      }
127
    }),
128
    new ExtractTextPlugin('[name].[contenthash:8].css')
Dan Abramov's avatar
Dan Abramov committed
129
130
  ]
};