-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwebpack.config.js
91 lines (84 loc) · 2.38 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
var webpack = require( 'webpack' ),
path = require( 'path' ),
CleanWebpackPlugin = require( 'clean-webpack-plugin' ),
ExtractTextPlugin = require( 'extract-text-webpack-plugin' );
// TODO autoprefixer:
// browsers: ['> 1%', 'last 2 versions', 'ff 17', 'opera 12.1', 'ie 8', 'ie 9', 'safari 7', 'safari 8'],
// map: true
var IS_HOT_UPDATE = ( process.env.NODE_ENV !== 'production' );
var scssLoader = [ 'style-loader', 'css-loader', 'autoprefixer-loader', 'sass-loader' ];
// if we're doing hot update, we want to render component SCSS inline.
// if not, we want to extract the text into a separate dist/[name].css file
if ( ! IS_HOT_UPDATE ) {
scssLoader.unshift();
scssLoader = ExtractTextPlugin.extract( { fallback: "style-loader", use: scssLoader } );
}
// create a list of plugins filtered based on whether we're developing locally (i.e. using Hot Update)
var plugins = [
new CleanWebpackPlugin( [ 'dist' ] ),
new ExtractTextPlugin( '[name].css' ),
IS_HOT_UPDATE ? new webpack.HotModuleReplacementPlugin() : false,
IS_HOT_UPDATE ? new webpack.NoEmitOnErrorsPlugin() : false, // don't hot-reload if there's an error in our code
new webpack.DefinePlugin( {
'process.env': {
// This has effect on the react lib size
'NODE_ENV': JSON.stringify( process.env.NODE_ENV ) // TODO switch depending on actual environment
}
} )
].filter( function( plugin ) {
return plugin !== false;
} );
module.exports = {
// progress: true,
externals: {
'react': 'React',
'react-dom': 'ReactDOM',
'react': 'React'
},
output: {
publicPath: '/assets/',
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
chunkFilename: '[id].js'
},
resolve: {
extensions: [ '.js', '.jsx' ],
modules: [ path.join( __dirname, "node_modules" ), path.resolve( __dirname, 'client' ) ]
},
stats: {
colors: true,
reasons: true
},
node: {
fs: "empty"
},
module: {
rules: [
{
test: /\.html$/,
use: 'html-loader'
},
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: [ 'react-hot-loader/webpack', 'babel-loader', 'eslint-loader' ],
include: [
path.join( __dirname, 'client' )
]
},
{
test: /\.json$/,
use: require.resolve( 'json-loader' )
},
{
test: /\.scss$/,
use: scssLoader
},
{
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
use: require.resolve('url-loader')+"?limit=10000&mimetype=image/svg+xml"
}
]
},
plugins: plugins
};