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