diff --git a/app.js b/app.js index 1ec1db78a..868ceee4c 100644 --- a/app.js +++ b/app.js @@ -32,17 +32,32 @@ app.use(helmet({ frameguard: false })); app.use(bodyParser.json()); -app.get('*.js', (req, res, next) => { - const accept = accepts(req); - if (accept.encoding(['gzip']) === 'gzip') { - req.url = `${req.url}.gz`; - res.set('Content-Encoding', 'gzip'); - } - next(); -}); +//============================================================================== +// STATIC FILES +//============================================================================== + +// If the application is in production mode, then add gzip rewriting for the +// content. +if (process.env.NODE_ENV === 'production') { + app.get('*.js', (req, res, next) => { + const accept = accepts(req); + if (accept.encoding(['gzip']) === 'gzip') { + req.url = `${req.url}.gz`; + res.set('Content-Encoding', 'gzip'); + } + + next(); + }); +} + app.use('/client', express.static(path.join(__dirname, 'dist'))); app.use('/public', express.static(path.join(__dirname, 'public'))); + +//============================================================================== +// VIEW CONFIGURATION +//============================================================================== + app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'ejs'); diff --git a/webpack.config.js b/webpack.config.js index 6a05f31b6..78b111579 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -37,7 +37,7 @@ const buildEmbeds = [ 'stream' ]; -module.exports = { +const config = { devtool: 'cheap-module-source-map', entry: Object.assign({}, { 'embed': [ @@ -142,13 +142,6 @@ module.exports = { }), new webpack.EnvironmentPlugin({ 'TALK_PLUGINS_JSON': '{}' - }), - new CompressionPlugin({ - asset: '[path].gz[query]', - algorithm: 'gzip', - test: /\.(js)$/, - threshold: 10240, - minRatio: 0.8 }) ], resolveLoader: { @@ -168,3 +161,15 @@ module.exports = { ] } }; + +if (process.env.NODE_ENV === 'production') { + config.plugins.push(new CompressionPlugin({ + asset: '[path].gz[query]', + algorithm: 'gzip', + test: /\.(js)$/, + threshold: 10240, + minRatio: 0.8 + })); +} + +module.exports = config;