2016-04-13 15:21:25 -04:00
|
|
|
var autoprefixer = require('autoprefixer');
|
2015-11-10 13:38:28 -05:00
|
|
|
var CopyWebpackPlugin = require('copy-webpack-plugin');
|
2015-09-02 15:08:58 -04:00
|
|
|
var path = require('path');
|
|
|
|
var webpack = require('webpack');
|
2015-10-13 15:40:51 -04:00
|
|
|
|
2015-09-04 01:26:56 -04:00
|
|
|
var routes = require('./server/routes.json');
|
2015-09-02 15:08:58 -04:00
|
|
|
|
2016-04-12 08:23:43 -04:00
|
|
|
|
|
|
|
function HtmlGeneratorPlugin (options) {
|
|
|
|
this.options = options;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
HtmlGeneratorPlugin.prototype.apply = function (compiler) {
|
|
|
|
var render = this.options.render;
|
|
|
|
var routes = this.options.routes;
|
|
|
|
|
|
|
|
compiler.plugin('emit', function (compilation, callback) {
|
|
|
|
var outputRoutes = {};
|
|
|
|
routes.forEach(function (route) {
|
|
|
|
var filename = route.view + '.html';
|
|
|
|
var content = render(route);
|
|
|
|
outputRoutes[route.pattern] = filename;
|
|
|
|
compilation.assets[filename] = {
|
|
|
|
source: function () {return content;},
|
|
|
|
size: function () {return content.length;}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
var routeJson = JSON.stringify(outputRoutes);
|
|
|
|
compilation.assets['routes.json'] = {
|
|
|
|
source: function () {return routeJson;},
|
|
|
|
size: function () {return routeJson.length;}
|
|
|
|
};
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-09-04 01:26:56 -04:00
|
|
|
// Prepare all entry points
|
|
|
|
var entry = {
|
2016-01-06 14:23:47 -05:00
|
|
|
init: './src/init.js'
|
2015-09-04 01:26:56 -04:00
|
|
|
};
|
|
|
|
routes.forEach(function (route) {
|
2015-11-10 13:38:28 -05:00
|
|
|
entry[route.view] = './src/views/' + route.view + '/' + route.view + '.jsx';
|
2015-09-04 01:26:56 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
// Config
|
2015-09-02 15:08:58 -04:00
|
|
|
module.exports = {
|
2015-09-04 01:26:56 -04:00
|
|
|
entry: entry,
|
2015-09-02 15:08:58 -04:00
|
|
|
devtool: 'source-map',
|
|
|
|
externals: {
|
|
|
|
'react': 'React',
|
2015-10-14 22:58:32 -04:00
|
|
|
'react/addons': 'React',
|
2015-11-16 09:40:11 -05:00
|
|
|
'react-dom': 'ReactDOM',
|
2016-03-18 11:51:22 -04:00
|
|
|
'react-intl': 'ReactIntl',
|
|
|
|
'redux': 'Redux'
|
2015-09-02 15:08:58 -04:00
|
|
|
},
|
|
|
|
output: {
|
2015-11-10 13:38:28 -05:00
|
|
|
path: path.resolve(__dirname, 'build'),
|
|
|
|
filename: 'js/[name].bundle.js'
|
2015-09-02 15:08:58 -04:00
|
|
|
},
|
|
|
|
module: {
|
|
|
|
loaders: [
|
|
|
|
{
|
|
|
|
test: /\.jsx$/,
|
|
|
|
loader: 'jsx-loader',
|
|
|
|
include: path.resolve(__dirname, 'src')
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.json$/,
|
2015-10-16 15:09:06 -04:00
|
|
|
loader: 'json-loader'
|
2015-09-02 15:08:58 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.scss$/,
|
2016-04-13 15:21:25 -04:00
|
|
|
loader: 'style!css!postcss-loader!sass'
|
2015-09-08 14:56:28 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(png|jpg|gif|eot|svg|ttf|woff)$/,
|
|
|
|
loader: 'url-loader'
|
2015-09-02 15:08:58 -04:00
|
|
|
}
|
|
|
|
]
|
2015-09-02 16:33:31 -04:00
|
|
|
},
|
2016-04-13 15:21:25 -04:00
|
|
|
postcss: function () {
|
|
|
|
return [autoprefixer({browsers: ['last 3 versions']})];
|
|
|
|
},
|
2015-10-07 11:29:17 -04:00
|
|
|
node: {
|
|
|
|
fs: 'empty'
|
|
|
|
},
|
2015-09-02 16:33:31 -04:00
|
|
|
plugins: [
|
2016-04-12 08:23:43 -04:00
|
|
|
new HtmlGeneratorPlugin({
|
|
|
|
render: require('./server/render.js'),
|
|
|
|
routes: routes
|
|
|
|
}),
|
2015-11-10 13:38:28 -05:00
|
|
|
new CopyWebpackPlugin([
|
2016-01-08 13:50:58 -05:00
|
|
|
{from: 'static'},
|
2016-01-14 08:16:02 -05:00
|
|
|
{from: 'intl', to: 'js'}
|
2015-11-10 13:38:28 -05:00
|
|
|
]),
|
2015-09-02 16:33:31 -04:00
|
|
|
new webpack.optimize.UglifyJsPlugin({
|
|
|
|
compress: {
|
|
|
|
warnings: false
|
|
|
|
}
|
|
|
|
}),
|
2015-11-19 10:28:53 -05:00
|
|
|
new webpack.optimize.OccurenceOrderPlugin()
|
2015-09-02 16:33:31 -04:00
|
|
|
]
|
2015-09-02 15:08:58 -04:00
|
|
|
};
|