/** * 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. */ var path = require('path'); var autoprefixer = require('autoprefixer'); var webpack = require('webpack'); var HtmlWebpackPlugin = require('html-webpack-plugin'); var ExtractTextPlugin = require('extract-text-webpack-plugin'); var url = require('url'); var paths = require('./paths'); var env = require('./env'); var homepagePath = require(paths.appPackageJson).homepage; var publicPath = homepagePath ? url.parse(homepagePath).pathname : '/'; if (!publicPath.endsWith('/')) { // Prevents incorrect paths in file-loader publicPath += '/'; } module.exports = { bail: true, devtool: 'source-map', entry: [ require.resolve('./polyfills'), path.join(paths.appSrc, 'index') ], output: { path: paths.appBuild, filename: 'static/js/[name].[chunkhash:8].js', chunkFilename: 'static/js/[name].[chunkhash:8].chunk.js', publicPath: publicPath }, resolve: { extensions: ['', '.js', '.json'], alias: { // This `alias` section can be safely removed after ejection. // We do this because `babel-runtime` may be inside `react-scripts`, // so when `babel-plugin-transform-runtime` imports it, it will not be // available to the app directly. This is a temporary solution that lets // us ship support for generators. However it is far from ideal, and // if we don't have a good solution, we should just make `babel-runtime` // a dependency in generated projects. // See https://github.com/facebookincubator/create-react-app/issues/255 'babel-runtime/regenerator': require.resolve('babel-runtime/regenerator') } }, resolveLoader: { root: paths.ownNodeModules, moduleTemplates: ['*-loader'] }, module: { preLoaders: [ { test: /\.js$/, loader: 'eslint', include: paths.appSrc } ], loaders: [ { test: /\.js$/, include: paths.appSrc, loader: 'babel', query: require('./babel.prod') }, { test: /\.css$/, include: [paths.appSrc, paths.appNodeModules], // 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') }, { test: /\.json$/, include: [paths.appSrc, paths.appNodeModules], loader: 'json' }, { test: /\.(jpg|png|gif|eot|svg|ttf|woff|woff2)(\?.*)?$/, include: [paths.appSrc, paths.appNodeModules], loader: 'file', query: { name: 'static/media/[name].[hash:8].[ext]' } }, { test: /\.(mp4|webm)(\?.*)?$/, include: [paths.appSrc, paths.appNodeModules], loader: 'url', query: { limit: 10000, name: 'static/media/[name].[hash:8].[ext]' } } ] }, eslint: { // 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 }, postcss: function() { return [autoprefixer]; }, plugins: [ new HtmlWebpackPlugin({ inject: true, template: paths.appHtml, favicon: paths.appFavicon, minify: { removeComments: true, collapseWhitespace: true, removeRedundantAttributes: true, useShortDoctype: true, removeEmptyAttributes: true, removeStyleLinkTypeAttributes: true, keepClosingSlash: true, minifyJS: true, minifyCSS: true, minifyURLs: true } }), new webpack.DefinePlugin(env), new webpack.optimize.OccurrenceOrderPlugin(), new webpack.optimize.DedupePlugin(), new webpack.optimize.UglifyJsPlugin({ compress: { screw_ie8: true, warnings: false }, mangle: { screw_ie8: true }, output: { comments: false, screw_ie8: true } }), new ExtractTextPlugin('static/css/[name].[contenthash:8].css') ] };