-
Notifications
You must be signed in to change notification settings - Fork 201
/
webpack.config.js
59 lines (48 loc) · 1.32 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
var fs = require('fs');
var path = require('path');
var webpack = require('webpack');
var CODE = __dirname+'/excercises';
var React = require('react');
makeIndex();
module.exports = {
devtool: 'eval',
entry: fs.readdirSync(CODE).reduce(function (entries, dir) {
if (isDirectory(path.join(CODE, dir)))
entries[dir] = path.join(CODE, dir, 'app.js');
return entries;
}, {}),
output: {
path: 'excercises/__build__',
filename: '[name].js',
chunkFilename: '[id].chunk.js',
publicPath: '/__build__/'
},
module: {
loaders: [
{ test: /\.json$/, loader: 'json-loader' },
{ test: /\.js$/, loader: 'jsx-loader?harmony' }
]
},
plugins: [
new webpack.optimize.CommonsChunkPlugin('shared.js')
]
};
function makeIndex () {
var list = fs.readdirSync(CODE).filter(function(dir) {
return isDirectory(path.join(CODE, dir));
}).map(function (dir) {
return React.DOM.li({}, React.DOM.a({href: '/'+dir}, dir.replace(/-/g, ' ')));
});
var markup = React.renderToStaticMarkup((
React.DOM.html({},
React.DOM.link({rel: 'stylesheet', href: '/shared.css'}),
React.DOM.body({id: "index"},
React.DOM.ul({}, list)
)
)
));
fs.writeFileSync('./excercises/index.html', markup);
}
function isDirectory(dir) {
return fs.lstatSync(dir).isDirectory();
}