ff-stream-web

git clone git://archive.git.mtrnord.blog/MTRNord/ff-stream-web.git
Log | Files | Refs | README | LICENSE

commit d9126bfbd6a59496585fab9bdf856edf521bb30d
parent 1ef986067e085400fd29227c30c7e62f8e72e8e3
Author: Konstantin Tarkus <hello@tarkus.me>
Date:   Thu, 12 Feb 2015 09:47:09 +0300

Update plugins section webpack.config.js; clean up server.js

And also update gulp-htmlmin and gulp-less npm modules

Diffstat:
Mpackage.json | 4++--
Msrc/server.js | 19++++++++++---------
Mwebpack.config.js | 47++++++++++++++++++++++++++++-------------------
3 files changed, 40 insertions(+), 30 deletions(-)

diff --git a/package.json b/package.json @@ -34,12 +34,12 @@ "gulp-changed": "^1.1.1", "gulp-csscomb": "^3.0.3", "gulp-gh-pages": "^0.4.0", - "gulp-htmlmin": "^1.0.0", + "gulp-htmlmin": "^1.1.0", "gulp-if": "^1.2.5", "gulp-imagemin": "^2.2.0", "gulp-jsbeautifier": "^0.0.4", "gulp-jshint": "^1.9.2", - "gulp-less": "^2.0.2", + "gulp-less": "^3.0.0", "gulp-load-plugins": "^0.8.0", "gulp-minify-css": "^0.4.5", "gulp-plumber": "^0.6.6", diff --git a/src/server.js b/src/server.js @@ -13,15 +13,6 @@ import fs from 'fs'; import path from 'path'; import express from 'express'; import React from 'react'; - -// Set global variables -global.__DEV__ = process.env.NODE_ENV == 'development'; -global.__SERVER__ = true; - -// The top-level React component + HTML template for it -var App = React.createFactory(require('./components/App')); -var templateFile = path.join(__dirname, 'templates/index.html'); -var template = _.template(fs.readFileSync(templateFile, 'utf8')); import Dispatcher from './core/Dispatcher'; import ActionTypes from './constants/ActionTypes'; import AppStore from './stores/AppStore'; @@ -31,14 +22,24 @@ var server = express(); server.set('port', (process.env.PORT || 5000)); server.use(express.static(path.join(__dirname))); +// // Page API +// ----------------------------------------------------------------------------- server.get('/api/page/*', function(req, res) { var path = req.path.substr(9); var page = AppStore.getPage(path); res.send(page); }); +// // Server-side rendering +// ----------------------------------------------------------------------------- + +// The top-level React component + HTML template for it +var App = React.createFactory(require('./components/App')); +var templateFile = path.join(__dirname, 'templates/index.html'); +var template = _.template(fs.readFileSync(templateFile, 'utf8')); + server.get('*', function(req, res) { var data = {description: ''}; var app = new App({ diff --git a/webpack.config.js b/webpack.config.js @@ -11,8 +11,8 @@ var argv = require('minimist')(process.argv.slice(2)); var DEBUG = !argv.release; -// Common configuration for both -// client-side and server-side bundles +// Common configuration chunk to be used for both +// client-side (app.js) and server-side (server.js) bundles var config = { output: { path: './build/', @@ -29,21 +29,8 @@ var config = { reasons: DEBUG }, - plugins: DEBUG ? [ - new webpack.DefinePlugin({ - '__DEV__': true, - '__SERVER__': false - }) - ] : [ - new webpack.DefinePlugin({ - 'process.env.NODE_ENV': '"production"', - '__DEV__': false, - '__SERVER__': false - }), - new webpack.optimize.DedupePlugin(), - new webpack.optimize.UglifyJsPlugin(), - new webpack.optimize.OccurenceOrderPlugin(), - new webpack.optimize.AggressiveMergingPlugin() + plugins: [ + new webpack.optimize.OccurenceOrderPlugin() ], resolve: { @@ -100,7 +87,20 @@ var config = { // Configuration for the client-side bundle var appConfig = update(config, { entry: {$set: './src/app.js'}, - output: {filename: {$set: 'app.js'}} + output: {filename: {$set: 'app.js'}}, + plugins: { + $push: [ + new webpack.DefinePlugin({ + 'process.env.NODE_ENV': DEBUG ? '"development"' : '"production"', + '__DEV__': DEBUG, + '__SERVER__': false + }) + ].concat(DEBUG ? [] : [ + new webpack.optimize.DedupePlugin(), + new webpack.optimize.UglifyJsPlugin(), + new webpack.optimize.AggressiveMergingPlugin() + ]) + } }); // Configuration for the server-side bundle @@ -113,13 +113,22 @@ var serverConfig = update(config, { target: {$set: 'node'}, externals: {$set: /^[a-z\-0-9]+$/}, node: {$set: { - console: true, + console: false, global: false, process: false, Buffer: false, __filename: false, __dirname: false }}, + plugins: { + $push: [ + new webpack.DefinePlugin({ + 'process.env.NODE_ENV': DEBUG ? '"development"' : '"production"', + '__DEV__': DEBUG, + '__SERVER__': true + }) + ] + }, module: {loaders: {$apply: function(loaders) { loaders.forEach(function(loader) { loader.loader = loader.loader.replace('style-loader!', '');