webpack.config.dev.js 2.08 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
16
17
var isInNodeModules = 'node_modules' ===
  path.basename(path.resolve(path.join(__dirname, '..')));
var relative = isInNodeModules ? '../..' : '.';
18

Dan Abramov's avatar
Dan Abramov committed
19
module.exports = {
20
21
22
23
24
  devtool: 'eval',
  entry: [
    './src/index.js',
    'webpack-dev-server/client?http://localhost:3000'
  ],
Dan Abramov's avatar
Dan Abramov committed
25
26
  output: {
    // Next line is not used in dev but WebpackDevServer crashes without it:
27
    path: path.join(__dirname, relative, 'build'),
Dan Abramov's avatar
Dan Abramov committed
28
29
30
31
    filename: 'bundle.js',
    publicPath: '/'
  },
  module: {
Dan Abramov's avatar
Dan Abramov committed
32
33
34
    preLoaders: [
      {
        test: /\.js$/,
35
36
        loader: 'eslint',
        include: path.resolve(__dirname, relative, 'src'),
Dan Abramov's avatar
Dan Abramov committed
37
38
      }
    ],
Dan Abramov's avatar
Dan Abramov committed
39
    loaders: [
Dan Abramov's avatar
Dan Abramov committed
40
41
      {
        test: /\.js$/,
42
        include: path.resolve(__dirname, relative, 'src'),
43
44
45
46
47
48
        loader: 'babel',
        query: {
          cacheDirectory: true,
          presets: ['es2015', 'es2016', 'react'],
          plugins: ['transform-object-rest-spread']
        }
Dan Abramov's avatar
Dan Abramov committed
49
      },
Dan Abramov's avatar
Dan Abramov committed
50
51
      {
        test: /\.css$/,
52
        include: path.resolve(__dirname, relative, 'src'),
Dan Abramov's avatar
Dan Abramov committed
53
54
55
        loader: 'style!css!postcss'
      },
      {
Dan Abramov's avatar
Dan Abramov committed
56
57
58
59
60
61
62
63
64
65
        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
66
67
68
      }
    ]
  },
69
70
71
72
73
  eslint: {
    configFile: path.join(__dirname, '.eslintrc')
  },
  postcss: function() {
    return [autoprefixer];
Dan Abramov's avatar
Dan Abramov committed
74
75
  },
  plugins: [
Max's avatar
Max committed
76
77
    new HtmlWebpackPlugin({
      inject: true,
Max's avatar
Max committed
78
      template: path.resolve(__dirname, relative, 'index.html'),
Max's avatar
Max committed
79
    }),
Dan Abramov's avatar
Dan Abramov committed
80
81
82
    new webpack.DefinePlugin({ 'process.env.NODE_ENV': '"development"' })
  ]
};