This repository has been archived by the owner on Apr 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
webpack.client.config.js
139 lines (128 loc) · 2.87 KB
/
webpack.client.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
// External dependencies
var baseConfig = require( './webpack.base.config' ),
ExtractTextPlugin = require( 'extract-text-webpack-plugin' ),
WebpackRTLPlugin = require( '@automattic/webpack-rtl-plugin' ),
merge = require( 'webpack-merge' ),
path = require( 'path' ),
fs = require( 'fs' ),
webpack = require( 'webpack' ),
NODE_ENV = process.env.NODE_ENV || 'development';
const vendorModules = [
'cookie-dough',
'creditcards',
'classnames',
'i18n-calypso',
'lodash',
'random-words',
'react',
'react-dom',
'react-redux',
'react-router',
'redux',
'redux-thunk',
'wpcom-xhr-request',
];
var config = merge.smart( baseConfig, {
devServer: {
port: 1337,
historyApiFallback: true
},
entry: {
app: [
'babel-polyfill',
path.join( __dirname, 'client' )
],
vendor: vendorModules
},
node: {
console: false,
process: true,
global: true,
Buffer: true,
__filename: 'mock',
__dirname: 'mock',
fs: 'empty'
},
output: {
path: path.resolve( __dirname, 'public/scripts' ),
publicPath: '/scripts/',
devtoolModuleFilenameTemplate: 'app:///[resource-path]',
filename: 'bundle.[hash].js',
sourceMapFilename: 'bundle.[hash].map.js'
},
plugins: [
new webpack.optimize.CommonsChunkPlugin( {
name: 'vendor',
filename: '[name].[hash].js'
} ),
new webpack.DefinePlugin( {
'process.env': {
NODE_ENV: JSON.stringify( NODE_ENV ),
BROWSER: JSON.stringify( true )
}
} ),
function() {
// We extract the bundle assets to a file to be used later for serving the correct hashed file
this.plugin( 'done', function( stats ) {
fs.writeFileSync(
path.join( path.resolve( __dirname, 'public/scripts' ), 'assets.json' ),
JSON.stringify( stats.toJson().assetsByChunkName )
);
} );
}
]
} );
if ( NODE_ENV === 'development' ) {
config = merge.smart( config, {
devServer: {
port: 1337,
historyApiFallback: true
},
module: {
loaders: [
{
test: /\.jsx?$/,
loaders: [ 'react-hot' ]
}
]
},
// Use a more performant type of sourcemaps for our development env
// For a comparison see: https://webpack.github.io/docs/configuration.html#devtool
devtool: 'eval'
} );
}
if ( NODE_ENV === 'production' ) {
config = merge.smart( config, {
module: {
loaders: [
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract( {
loader: [
'css?modules&importLoaders=1&localIdentName=[path][local]&camelCase=dashes',
'postcss',
'sass'
]
} )
}
]
},
plugins: [
new ExtractTextPlugin( {
filename: '../styles/bundle.[contenthash].css',
allChunks: true
} ),
new WebpackRTLPlugin( { filename: '../styles/bundle.[contenthash].rtl.css' } ),
new webpack.optimize.UglifyJsPlugin( {
sourceMap: !! config.devtool,
output: {
comments: false
},
compress: {
warnings: false
}
} )
]
} );
}
module.exports = config;