forked from mozilla/donate.mozilla.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
52 lines (46 loc) · 1.59 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
var SimpleHtmlPrecompiler = require('simple-html-precompiler');
var path = require('path');
var React = require('react');
require('babel/register');
var Router = require('react-router');
var routes = require('./components/routes.jsx');
var paths = require('./scripts/paths.js');
var currencies = require('./scripts/currencies.js');
module.exports = {
entry: "./components/client.jsx",
output: {
filename: '[name].js',
chunkFilename: '[id].chunk.js',
path: path.join('public')
},
resolve: {
extensions: ['', '.js', '.jsx']
},
module: {
loaders: [
{ test: /\.js$/, loaders: ['babel-loader'], exclude: ['node_modules'] },
{ test: /\.jsx$/, loaders: ['babel-loader'] },
{ test: /\.json$/, loaders: ['json-loader'] }
]
},
plugins: [
new SimpleHtmlPrecompiler(paths, function(outputPath, callback) {
Router.run(routes, outputPath, function (Handler, state) {
var values = {};
var Index = React.createFactory(require('./pages/index.jsx'));
var Page = React.createFactory(Handler);
if (currencies[state.params.currency]) {
values = currencies[state.params.currency];
}
if(state.params.locale) {
values = Object.assign({messages: require(path.join(__dirname, 'locales/' + state.params.locale +'.json'))}, values);
} else {
values = Object.assign({messages: require(path.join(__dirname, 'locales/en-US.json'))}, values);
}
callback(React.renderToStaticMarkup(Index({
markup: React.renderToStaticMarkup(Page(values))
})));
});
})
]
};