forked from shanewilson/react-webpack-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
40 lines (31 loc) · 1.26 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
'use strict';
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var production = process.env.NODE_ENV === 'production';
var config = production ? require('./webpack.prod.config.js') : require('./webpack.base.config.js');
config.module.loaders = config.module.loaders.concat([
{test: /\.jsx?$/, loader: 'babel?optional=runtime', exclude: /node_modules/},
{test: /\.css$/, loader: ExtractTextPlugin.extract('style', 'css?importLoaders=1!postcss')}
]);
config.plugins = config.plugins.concat(
[
new ExtractTextPlugin(config.output.css),
function() {
this.plugin('done', function(stats) {
var fs = require('graceful-fs');
fs.readFile('./src/index.html', 'utf8', function(readErr, data) {
if (readErr) return console.log(readErr);
data = data.replace(
'</head>',
'<link rel="stylesheet" href="/js/style.css"/></head>'
);
if (production) {
data = config.revFiles(data, stats.toJson().assets);
}
fs.writeFile('./dist/index.html', data, 'utf8', function(writeErr) {
if (writeErr) return console.log(writeErr);
});
});
});
}
]);
module.exports = config;