forked from react-bootstrap/dom-helpers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.configs.js
106 lines (85 loc) · 2.86 KB
/
webpack.configs.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
var webpack = require('webpack');
var pkg = require('./package.json')
module.exports = {
dev: makeConfig({
hot: true,
devtool: 'source-map',
entry: './dev/dev.jsx',
output: {
filename: 'bundle.js',
path: __dirname
}
}),
test: makeConfig({
devtool: 'inline-source-map',
loaders: [
{ test: /sinon-chai/, loader: 'imports?define=>false' }
]
})
}
function makeConfig(options){
var entry = options.entry
, plugins = options.plugins || []
var loaders = [
{ test: /\.css$/, loader: options.extractStyles
? ExtractTextPlugin.extract('style-loader', 'css-loader')
: 'style-loader!css-loader' },
{ test: /\.less$/, loader: options.extractStyles
? ExtractTextPlugin.extract('style-loader', 'css-loader!less-loader')
: 'style-loader!css-loader!less-loader' },
{ test: /\.gif$/, loader: 'url-loader?mimetype=image/png' },
{ test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'url-loader?limit=10000&minetype=application/font-woff' },
{ test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'file-loader?name=[name].[ext]' },
{ test: /\.jsx$|\.js$/, loader: 'babel-loader', exclude: /node_modules/ }
];
if (options.hot){
loaders.splice(loaders.length - 1,0,
{ test: /\.jsx$|\.js$/, loader: 'react-hot-loader', exclude: /node_modules/ })
plugins.push(
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin())
entry = [
'webpack-dev-server/client?http://localhost:8080',
'webpack/hot/only-dev-server',
entry
]
}
if (options.loaders)
loaders = loaders.concat(options.loaders)
if (options.minimize)
plugins.push(
new webpack.optimize.UglifyJsPlugin(),
new webpack.optimize.DedupePlugin(),
new webpack.NoErrorsPlugin())
else
plugins.push(
new webpack.DefinePlugin({ '__VERSION__': JSON.stringify(pkg.version) }));
if ( options.production || options.minimize )
plugins.push(new webpack.DefinePlugin({
'__VERSION__': JSON.stringify(pkg.version),
'process.env': { NODE_ENV: JSON.stringify("production") }
}))
if (options.extractStyles)
plugins.push(
new ExtractTextPlugin(options.styleName || "styles.css", {
allChunks: true
}))
if (options.banner) {
plugins.push(
new webpack.BannerPlugin(
'v' + JSON.stringify(pkg.version) + ' | (c) ' + (new Date).getFullYear() + ' Jason Quense | '
+ 'https://github.com/jquense/react-widgets/blob/master/License.txt'
, { entryOnly : true }))
}
return {
cache: options.cache !== false,
devtool: options.devtool,
entry: entry,
output: options.output,
externals: options.externals,
resolve: { extensions: ['', '.js', '.jsx'] },
module: { loaders: loaders },
plugins: plugins,
node: { Buffer: false }
}
}