webpack.config.dev.js 2.29 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
14
var path = require('path');
var autoprefixer = require('autoprefixer');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');

Dan Abramov's avatar
Dan Abramov committed
15
var isInNodeModules = 'node_modules' ===
16
17
  path.basename(path.resolve(path.join(__dirname, '..', '..')));
var relative = isInNodeModules ? '../../..' : '..';
18

Dan Abramov's avatar
Dan Abramov committed
19
module.exports = {
20
21
  devtool: 'eval',
  entry: [
22
    require.resolve('webpack-dev-server/client') + '?http://localhost:3000',
23
    require.resolve('webpack/hot/dev-server'),
24
    './src/index.js'
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: path.join(__dirname, relative, 'build'),
Dan Abramov's avatar
Dan Abramov committed
29
    pathinfo: true,
Dan Abramov's avatar
Dan Abramov committed
30
31
32
    filename: 'bundle.js',
    publicPath: '/'
  },
33
34
35
36
  resolveLoader: {
    root: path.join(__dirname, '..', 'node_modules'),
    moduleTemplates: ['*-loader']
  },
Dan Abramov's avatar
Dan Abramov committed
37
  module: {
Dan Abramov's avatar
Dan Abramov committed
38
39
40
    preLoaders: [
      {
        test: /\.js$/,
41
42
        loader: 'eslint',
        include: path.resolve(__dirname, relative, 'src'),
Dan Abramov's avatar
Dan Abramov committed
43
44
      }
    ],
Dan Abramov's avatar
Dan Abramov committed
45
    loaders: [
Dan Abramov's avatar
Dan Abramov committed
46
47
      {
        test: /\.js$/,
48
        include: path.resolve(__dirname, relative, 'src'),
49
        loader: 'babel',
50
        query: require('./babel.dev')
Dan Abramov's avatar
Dan Abramov committed
51
      },
Dan Abramov's avatar
Dan Abramov committed
52
53
      {
        test: /\.css$/,
54
        include: path.resolve(__dirname, relative, 'src'),
Dan Abramov's avatar
Dan Abramov committed
55
56
57
        loader: 'style!css!postcss'
      },
      {
Dan Abramov's avatar
Dan Abramov committed
58
59
60
61
62
63
64
65
66
67
        test: /\.json$/,
        loader: 'json'
      },
      {
        test: /\.(jpg|png|gif|eot|svg|ttf|woff|woff2)$/,
        loader: 'file',
      },
      {
        test: /\.(mp4|webm)$/,
        loader: 'url?limit=10000'
Dan Abramov's avatar
Dan Abramov committed
68
69
70
      }
    ]
  },
71
  eslint: {
72
73
    configFile: path.join(__dirname, 'eslint.js'),
    useEslintrc: false
74
75
76
  },
  postcss: function() {
    return [autoprefixer];
Dan Abramov's avatar
Dan Abramov committed
77
78
  },
  plugins: [
Max's avatar
Max committed
79
80
    new HtmlWebpackPlugin({
      inject: true,
Max's avatar
Max committed
81
      template: path.resolve(__dirname, relative, 'index.html'),
Max's avatar
Max committed
82
    }),
83
84
85
    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
86
87
  ]
};