webpack.config.dev.js 3.12 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 paths = require('./paths');
15

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