webpack.config.dev.js 2.62 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');

15
16
// TODO: hide this behind a flag and eliminate dead code on eject.
// This shouldn't be exposed to the user.
Dan Abramov's avatar
Dan Abramov committed
17
var isInNodeModules = 'node_modules' ===
18
  path.basename(path.resolve(path.join(__dirname, '..', '..')));
19
20
21
22
23
24
25
26
var relativePath = isInNodeModules ? '../../..' : '..';
if (process.argv[2] === '--debug-template') {
  relativePath = '../template';
}
var srcPath = path.resolve(__dirname, relativePath, 'src');
var nodeModulesPath = path.join(__dirname, '..', 'node_modules');
var indexHtmlPath = path.resolve(__dirname, relativePath, 'index.html');
var buildPath = path.join(__dirname, isInNodeModules ? '../../..' : '..', 'build');
27

Dan Abramov's avatar
Dan Abramov committed
28
module.exports = {
29
30
  devtool: 'eval',
  entry: [
31
    require.resolve('webpack-dev-server/client') + '?http://localhost:3000',
32
    require.resolve('webpack/hot/dev-server'),
33
    path.join(srcPath, 'index')
34
  ],
Dan Abramov's avatar
Dan Abramov committed
35
36
  output: {
    // Next line is not used in dev but WebpackDevServer crashes without it:
37
    path: buildPath,
Dan Abramov's avatar
Dan Abramov committed
38
    pathinfo: true,
Dan Abramov's avatar
Dan Abramov committed
39
40
41
    filename: 'bundle.js',
    publicPath: '/'
  },
42
43
44
  resolve: {
    extensions: ['', '.js'],
  },
45
  resolveLoader: {
46
    root: nodeModulesPath,
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: srcPath,
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: srcPath,
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: srcPath,
Dan Abramov's avatar
Dan Abramov committed
67
68
69
        loader: 'style!css!postcss'
      },
      {
Dan Abramov's avatar
Dan Abramov committed
70
71
72
73
74
75
76
77
78
79
        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
80
81
82
      }
    ]
  },
83
  eslint: {
84
85
    configFile: path.join(__dirname, 'eslint.js'),
    useEslintrc: false
86
87
88
  },
  postcss: function() {
    return [autoprefixer];
Dan Abramov's avatar
Dan Abramov committed
89
90
  },
  plugins: [
Max's avatar
Max committed
91
92
    new HtmlWebpackPlugin({
      inject: true,
93
      template: indexHtmlPath,
Max's avatar
Max committed
94
    }),
95
96
97
    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
98
99
  ]
};