forked from markfinger/python-react
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.webpack.js
More file actions
76 lines (72 loc) · 1.96 KB
/
example.webpack.js
File metadata and controls
76 lines (72 loc) · 1.96 KB
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
var path = require('path');
var webpack = require('webpack');
var autoprefixer = require('autoprefixer-core');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = function(opts) {
var config = {
context: __dirname,
entry: './mount',
output: {
filename: '[name]-[hash].js',
pathinfo: opts.context.DEBUG
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: (opts.hmr ? 'react-hot-loader!': '') + 'babel-loader'
},
{
test: /\.css$/,
loader: opts.hmr ?
'style!css-loader?sourceMap!postcss-loader' :
ExtractTextPlugin.extract('style', 'css-loader?sourceMap!postcss-loader')
},
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url-loader?limit=10000&mimetype=application/font-woff'
},
{
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader'
}
]
},
postcss: [autoprefixer],
resolve: {
alias: {
__react_mount_component__: opts.context.component
}
},
plugins: [
// Define the variables in `./mount.js` that webpack will replace with data from python
new webpack.DefinePlugin({
__react_mount_props_variable__: opts.context.props_var,
__react_mount_container__: JSON.stringify(opts.context.container)
}),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.NoErrorsPlugin(),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(
opts.context.DEBUG ? 'development' : 'production'
)
}
})
],
devtool: opts.context.DEBUG ? 'eval-source-map' : 'source-map'
};
if (!opts.hmr) {
// Move css assets into separate files
config.plugins.push(new ExtractTextPlugin('[name]-[contenthash].css'));
}
if (!opts.context.DEBUG) {
// Remove duplicates and activate compression
config.plugins.push(
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin()
);
}
return config;
};