webpack.config.dev.js 2.72 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
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');
Dan Abramov's avatar
Dan Abramov committed
26
var faviconPath = path.resolve(__dirname, relativePath, 'favicon.ico');
27
var buildPath = path.join(__dirname, isInNodeModules ? '../../..' : '..', 'build');
28

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