webpack.config.dev.js 3.4 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

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