webpack.config.dev.js 2.88 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
var relativePath = isInNodeModules ? '../../..' : '..';
Dan Abramov's avatar
Dan Abramov committed
20
21
22
23
var isInDebugMode = process.argv.some(arg =>
  arg.indexOf('--debug-template') > -1
);
if (isInDebugMode) {
24
25
26
  relativePath = '../template';
}
var srcPath = path.resolve(__dirname, relativePath, 'src');
27
var rootNodeModulesPath = path.resolve(__dirname, relativePath, 'node_modules');
28
29
var nodeModulesPath = path.join(__dirname, '..', 'node_modules');
var indexHtmlPath = path.resolve(__dirname, relativePath, 'index.html');
Dan Abramov's avatar
Dan Abramov committed
30
var faviconPath = path.resolve(__dirname, relativePath, 'favicon.ico');
31
var buildPath = path.join(__dirname, isInNodeModules ? '../../..' : '..', 'build');
32

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