This repository has been archived by the owner on Nov 11, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
webpack.config.js
143 lines (137 loc) · 4.05 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
var fs = require('fs')
var path = require('path')
var combineLoaders = require('webpack-combine-loaders')
var resolve = require('resolve')
var webpack = require('webpack')
var NODE_MODULES_RE = /node_modules/
var ENTRY_RE = /react-heatpack[\\/]entry.js$/
/**
* Find the node_modules directory which will be resolved from a given dir.
*/
function findNodeModules(cwd) {
var parts = cwd.split(path.sep)
while (parts.length > 0) {
var target = path.join(parts.join(path.sep), 'node_modules')
if (fs.existsSync(target)) {
return target
}
parts.pop()
}
}
var reactPath
var reactDOMPath
try {
reactPath = resolve.sync('react', {basedir: process.cwd()})
reactDOMPath = resolve.sync('react-dom', {basedir: process.cwd()})
}
catch (e) {
reactPath = require.resolve('react')
reactDOMPath = require.resolve('react-dom')
}
/**
* We need to special-case exclusion to allow the heatpack entry module to be
* processed by loaders, as it will be under global node_modules.
*/
function excludeJS(absPath) {
if (ENTRY_RE.test(absPath)) {
return false
}
return NODE_MODULES_RE.test(absPath)
}
module.exports = function config(options) {
return {
devtool: 'cheap-module-eval-source-map',
entry: [
// Polyfill EventSource for IE, as webpack-hot-middleware/client uses it
require.resolve('eventsource-polyfill'),
require.resolve('webpack-hot-middleware/client'),
options.entry
],
output: {
path: __dirname + '/build',
filename: 'bundle.js',
publicPath: '/'
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development')
})
],
resolve: {
alias: {
'babel-runtime': path.join(findNodeModules(__dirname), 'babel-runtime'),
'react-heatpack-react-alias': reactPath,
'react-heatpack-react-dom-alias': reactDOMPath,
'react-heatpack-script-alias': options.script
},
extensions: ['', '.js', '.jsx', '.json'],
root: process.cwd(),
fallback: [findNodeModules(__dirname)]
},
module: {
loaders: [
{
test: /\.jsx?$/,
loader: require.resolve('babel-loader'),
exclude: excludeJS,
query: {
presets: [
require.resolve('babel-preset-es2015'),
require.resolve('babel-preset-react'),
require.resolve('babel-preset-stage-0')
],
plugins: [
require.resolve('babel-plugin-transform-runtime'),
require.resolve('babel-plugin-transform-react-display-name'),
[require.resolve('babel-plugin-react-transform'), {
transforms: [{
transform: require.resolve('react-transform-hmr'),
imports: [reactPath],
locals: ['module']
}, {
transform: require.resolve('react-transform-catch-errors'),
imports: [reactPath, require.resolve('redbox-noreact')]
}]
}]
]
}
},
{
test: /\.json$/,
loader: require.resolve('json-loader')
},
{
test: /\.css$/,
loader: combineLoaders([
{loader: require.resolve('style-loader')},
{loader: require.resolve('css-loader'), query: {minimize: false}}
]) + '!' + require.resolve('autoprefixer-loader')
},
{
test: /\.(gif|png)$/,
loader: require.resolve('url-loader'),
query: {
limit: 10240
}
},
{
test: /\.jpe?g$/,
loader: require.resolve('file-loader')
},
{
test: /\.(otf|svg|ttf|woff|woff2)(\?v=\d+\.\d+\.\d+)?$/,
loader: require.resolve('url-loader'),
query: {
limit: 10240
}
},
{
test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
loader: require.resolve('file-loader')
}
]
}
}
}