webpack.config.dev.js 3.39 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 CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
15
var WatchMissingNodeModulesPlugin = require('../scripts/utils/WatchMissingNodeModulesPlugin');
16
var paths = require('./paths');
17
var env = require('./env');
18

Dan Abramov's avatar
Dan Abramov committed
19
module.exports = {
20
21
  devtool: 'eval',
  entry: [
22
    require.resolve('webpack-dev-server/client') + '?/',
23
    require.resolve('webpack/hot/dev-server'),
24
    require.resolve('./polyfills'),
25
    path.join(paths.appSrc, 'index')
26
  ],
Dan Abramov's avatar
Dan Abramov committed
27
28
  output: {
    // Next line is not used in dev but WebpackDevServer crashes without it:
29
    path: paths.appBuild,
Dan Abramov's avatar
Dan Abramov committed
30
    pathinfo: true,
31
    filename: 'static/js/bundle.js',
Dan Abramov's avatar
Dan Abramov committed
32
33
    publicPath: '/'
  },
34
  resolve: {
Dan Abramov's avatar
Dan Abramov committed
35
    extensions: ['', '.js', '.json'],
36
37
38
39
40
41
42
43
44
45
46
    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')
    }
47
  },
48
  resolveLoader: {
49
    root: paths.ownNodeModules,
50
51
    moduleTemplates: ['*-loader']
  },
Dan Abramov's avatar
Dan Abramov committed
52
  module: {
Dan Abramov's avatar
Dan Abramov committed
53
54
55
    preLoaders: [
      {
        test: /\.js$/,
56
        loader: 'eslint',
57
        include: paths.appSrc,
Dan Abramov's avatar
Dan Abramov committed
58
59
      }
    ],
Dan Abramov's avatar
Dan Abramov committed
60
    loaders: [
Dan Abramov's avatar
Dan Abramov committed
61
62
      {
        test: /\.js$/,
63
        include: paths.appSrc,
64
        loader: 'babel',
65
        query: require('./babel.dev')
Dan Abramov's avatar
Dan Abramov committed
66
      },
Dan Abramov's avatar
Dan Abramov committed
67
68
      {
        test: /\.css$/,
69
        include: [paths.appSrc, paths.appNodeModules],
Dan Abramov's avatar
Dan Abramov committed
70
71
72
        loader: 'style!css!postcss'
      },
      {
Dan Abramov's avatar
Dan Abramov committed
73
        test: /\.json$/,
74
        include: [paths.appSrc, paths.appNodeModules],
Dan Abramov's avatar
Dan Abramov committed
75
76
77
        loader: 'json'
      },
      {
78
        test: /\.(jpg|png|gif|eot|svg|ttf|woff|woff2)(\?.*)?$/,
79
        include: [paths.appSrc, paths.appNodeModules],
Dan Abramov's avatar
Dan Abramov committed
80
        loader: 'file',
81
82
83
        query: {
          name: 'static/media/[name].[ext]'
        }
Dan Abramov's avatar
Dan Abramov committed
84
85
      },
      {
86
        test: /\.(mp4|webm)(\?.*)?$/,
87
        include: [paths.appSrc, paths.appNodeModules],
88
89
90
91
92
        loader: 'url',
        query: {
          limit: 10000,
          name: 'static/media/[name].[ext]'
        }
Dan Abramov's avatar
Dan Abramov committed
93
94
95
      }
    ]
  },
96
  eslint: {
97
98
    configFile: path.join(__dirname, 'eslint.js'),
    useEslintrc: false
99
100
101
  },
  postcss: function() {
    return [autoprefixer];
Dan Abramov's avatar
Dan Abramov committed
102
103
  },
  plugins: [
Max's avatar
Max committed
104
105
    new HtmlWebpackPlugin({
      inject: true,
106
107
      template: paths.appHtml,
      favicon: paths.appFavicon,
Max's avatar
Max committed
108
    }),
109
    new webpack.DefinePlugin(env),
110
    // Note: only CSS is currently hot reloaded
111
    new webpack.HotModuleReplacementPlugin(),
112
113
    new CaseSensitivePathsPlugin(),
    new WatchMissingNodeModulesPlugin(paths.appNodeModules)
Dan Abramov's avatar
Dan Abramov committed
114
115
  ]
};