1+ var path = require ( 'path' ) ;
2+ var webpack = require ( 'webpack' ) ;
3+ var autoprefixer = require ( 'autoprefixer-core' ) ;
4+ var ExtractTextPlugin = require ( 'extract-text-webpack-plugin' ) ;
5+
6+ module . exports = function ( opts ) {
7+ var config = {
8+ context : __dirname ,
9+ entry : './mount' ,
10+ output : {
11+ filename : '[name]-[hash].js' ,
12+ pathinfo : opts . context . DEBUG
13+ } ,
14+ module : {
15+ loaders : [
16+ {
17+ test : / \. j s x ? $ / ,
18+ exclude : / ( n o d e _ m o d u l e s | b o w e r _ c o m p o n e n t s ) / ,
19+ loader : ( opts . hmr ? 'react-hot-loader!' : '' ) + 'babel-loader'
20+ } ,
21+ {
22+ test : / \. c s s $ / ,
23+ loader : opts . hmr ?
24+ 'style!css-loader?sourceMap!postcss-loader' :
25+ ExtractTextPlugin . extract ( 'style' , 'css-loader?sourceMap!postcss-loader' )
26+ } ,
27+ {
28+ test : / \. w o f f ( 2 ) ? ( \? v = [ 0 - 9 ] \. [ 0 - 9 ] \. [ 0 - 9 ] ) ? $ / ,
29+ loader : 'url-loader?limit=10000&mimetype=application/font-woff'
30+ } ,
31+ {
32+ test : / \. ( t t f | e o t | s v g ) ( \? v = [ 0 - 9 ] \. [ 0 - 9 ] \. [ 0 - 9 ] ) ? $ / ,
33+ loader : 'file-loader'
34+ }
35+ ]
36+ } ,
37+ postcss : [ autoprefixer ] ,
38+ resolve : {
39+ alias : {
40+ __react_mount_component__ : opts . context . component
41+ }
42+ } ,
43+ plugins : [
44+ // Define the variables in `./mount.js` that webpack will replace with data from python
45+ new webpack . DefinePlugin ( {
46+ __react_mount_props_variable__ : opts . context . props_var ,
47+ __react_mount_container__ : JSON . stringify ( opts . context . container )
48+ } ) ,
49+ new webpack . optimize . OccurrenceOrderPlugin ( ) ,
50+ new webpack . NoErrorsPlugin ( ) ,
51+ new webpack . DefinePlugin ( {
52+ 'process.env' : {
53+ NODE_ENV : JSON . stringify (
54+ opts . context . DEBUG ? 'development' : 'production'
55+ )
56+ }
57+ } )
58+ ] ,
59+ devtool : opts . context . DEBUG ? 'eval-source-map' : 'source-map'
60+ } ;
61+
62+ if ( ! opts . hmr ) {
63+ // Move css assets into separate files
64+ config . plugins . push ( new ExtractTextPlugin ( '[name]-[contenthash].css' ) ) ;
65+ }
66+
67+ if ( ! opts . context . DEBUG ) {
68+ // Remove duplicates and activate compression
69+ config . plugins . push (
70+ new webpack . optimize . DedupePlugin ( ) ,
71+ new webpack . optimize . UglifyJsPlugin ( )
72+ ) ;
73+ }
74+
75+ return config ;
76+ } ;
0 commit comments