webpack.config.dev.js 2.8 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
27
28
  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
29
var faviconPath = path.resolve(__dirname, relativePath, 'favicon.ico');
30
var buildPath = path.join(__dirname, isInNodeModules ? '../../..' : '..', 'build');
31

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