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');
|
2016-04-28 15:40:50 -04:00
|
|
|
var gitsha = require('git-bundle-sha');
|
2016-04-18 14:07:11 -04:00
|
|
|
var MustacheRendererPlugin = require('./mustache-renderer-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
|
|
|
|
2016-04-18 14:07:11 -04:00
|
|
|
var routes = require('./src/routes.json');
|
2016-04-12 08:23:43 -04:00
|
|
|
|
2016-05-11 18:44:54 -04:00
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
|
|
routes = routes.concat(require('./src/routes-dev.json'));
|
|
|
|
}
|
|
|
|
|
2016-04-28 15:40:50 -04:00
|
|
|
var VersionPlugin = function (options) {
|
|
|
|
this.options = options || {};
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
VersionPlugin.prototype.apply = function (compiler) {
|
|
|
|
var addVersion = function (compilation, versionId, callback) {
|
|
|
|
compilation.assets['version.txt'] = {
|
|
|
|
source: function () {return versionId;},
|
|
|
|
size: function () {return versionId.length;}
|
|
|
|
};
|
|
|
|
callback();
|
|
|
|
};
|
|
|
|
var plugin = this;
|
|
|
|
compiler.plugin('emit', function (compilation, callback) {
|
|
|
|
var sha = process.env.WWW_VERSION;
|
|
|
|
if (!sha) {
|
|
|
|
gitsha(plugin.options, function (err, sha) {
|
|
|
|
if (err) return callback(err);
|
|
|
|
return addVersion(compilation, sha, callback);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return addVersion(compilation, sha, callback);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-09-04 01:26:56 -04:00
|
|
|
// Prepare all entry points
|
|
|
|
var entry = {
|
2016-05-16 12:36:28 -04:00
|
|
|
common: [
|
|
|
|
// Vendor
|
|
|
|
'raven-js',
|
|
|
|
'react',
|
|
|
|
'react-dom',
|
|
|
|
'react-intl',
|
|
|
|
'redux',
|
|
|
|
// Init
|
|
|
|
'./src/init.js'
|
|
|
|
]
|
2015-09-04 01:26:56 -04:00
|
|
|
};
|
|
|
|
routes.forEach(function (route) {
|
2016-04-09 13:07:21 -04:00
|
|
|
if (!route.redirect) {
|
2016-04-21 16:16:59 -04:00
|
|
|
entry[route.name] = './src/views/' + route.view + '.jsx';
|
2016-04-09 13:07:21 -04:00
|
|
|
}
|
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,
|
2016-06-02 15:27:32 -04:00
|
|
|
devtool: 'eval',
|
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
|
|
|
},
|
2016-06-02 15:25:02 -04:00
|
|
|
{
|
|
|
|
test: /\.css$/,
|
|
|
|
loader: 'style!css!postcss-loader'
|
|
|
|
},
|
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
|
|
|
}
|
2016-06-02 15:25:02 -04:00
|
|
|
],
|
|
|
|
noParse: /node_modules\/google-libphonenumber\/dist/
|
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-28 15:40:50 -04:00
|
|
|
new VersionPlugin({length: 5}),
|
2016-04-18 14:07:11 -04:00
|
|
|
new MustacheRendererPlugin({
|
|
|
|
templatePath: path.resolve(__dirname, './src/template.html'),
|
|
|
|
routes: routes,
|
|
|
|
config: require('./src/template-config.js')
|
2016-04-12 08:23:43 -04:00
|
|
|
}),
|
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
|
|
|
|
}
|
|
|
|
}),
|
2016-05-16 12:36:28 -04:00
|
|
|
new webpack.DefinePlugin({
|
2016-05-17 15:57:23 -04:00
|
|
|
'process.env.NODE_ENV': '"' + (process.env.NODE_ENV || 'development') + '"',
|
|
|
|
'process.env.SENTRY_DSN': '"' + (process.env.SENTRY_DSN || '') + '"'
|
2016-05-16 12:36:28 -04:00
|
|
|
}),
|
|
|
|
new webpack.optimize.CommonsChunkPlugin('common', 'js/common.bundle.js'),
|
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
|
|
|
};
|