From 7e5ad190a11c14486e45c3557006acea7fc29b35 Mon Sep 17 00:00:00 2001 From: Addy Osmani Date: Sun, 2 Oct 2016 22:37:21 -0700 Subject: [PATCH 01/20] Add babelrc --- .babelrc | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .babelrc diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..93fbaa3 --- /dev/null +++ b/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["es2015", "stage-0", "react"] +} \ No newline at end of file From cfa5f17badec91602279d748ebfc209ad5d1e821 Mon Sep 17 00:00:00 2001 From: Addy Osmani Date: Sun, 2 Oct 2016 22:37:28 -0700 Subject: [PATCH 02/20] Add list to gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1758d98..cbda785 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /public/build /node_modules -/public/sw-toolbox.js \ No newline at end of file +/public/sw-toolbox.js +dist \ No newline at end of file From 24223b541fa0011b007368d88f1707ee9cd49f2c Mon Sep 17 00:00:00 2001 From: Addy Osmani Date: Sun, 2 Oct 2016 22:37:43 -0700 Subject: [PATCH 03/20] Update nwb.config to latest loader, babel requirements --- nwb.config.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/nwb.config.js b/nwb.config.js index b7ea788..0e2beff 100644 --- a/nwb.config.js +++ b/nwb.config.js @@ -1,13 +1,21 @@ module.exports = { type: 'react-app', babel: { - loose: 'all' + loose: 'all', + stage: false, + presets: ['es2015', 'stage-0', 'react'] }, webpack: { + loaders: { + babel: { + babelrc: true, + cacheDirectory: true + } + }, plugins: { define: { __VERSION__: JSON.stringify(require('./package.json').version) } - } + } } -} +} \ No newline at end of file From 47510df4b7e53c25b8f64230f02a18662177d1b0 Mon Sep 17 00:00:00 2001 From: Addy Osmani Date: Sun, 2 Oct 2016 22:37:59 -0700 Subject: [PATCH 04/20] Bump package.json to latest deps --- package.json | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index ed72d62..e9d3b08 100644 --- a/package.json +++ b/package.json @@ -23,24 +23,28 @@ }, "main": "server.js", "dependencies": { + "babel-preset-es2015": "^6.16.0", + "babel-preset-react": "^6.16.0", + "babel-preset-stage-0": "^6.16.0", + "babel-register": "^6.16.0", "ejs": "^2.4.1", - "eslint-config-jonnybuchanan": "2.0.3", - "events": "1.1.0", + "eslint-config-jonnybuchanan": "4.6.0", + "events": "1.1.1", "express": "^4.13.4", - "firebase": "2.4.2", - "history": "2.1.1", + "firebase": "3.4.1", + "history": "4.2.0", "isomorphic-fetch": "^2.2.1", - "nwb": "0.8.1", + "nwb": "0.12.2", "object-assign": "^4.1.0", - "react": "15.0.2", - "react-dom": "15.0.2", - "react-router": "2.4.0", - "react-timeago": "3.0.0", - "reactfire": "0.7.0", - "scroll-behavior": "0.5.0", - "setimmediate": "1.0.4", - "sw-precache": "^3.1.1", + "react": "15.3.2", + "react-dom": "15.3.2", + "react-router": "2.8.1", + "react-timeago": "3.1.3", + "reactfire": "1.0.0", + "scroll-behavior": "0.8.1", + "setimmediate": "1.0.5", + "sw-precache": "^4.1.0", "sw-toolbox": "^3.1.1", "url-parse": "^1.1.1" } -} +} \ No newline at end of file From 232a92a5e8ec3ca144b1d26e8bf211a072c00c11 Mon Sep 17 00:00:00 2001 From: Addy Osmani Date: Sun, 2 Oct 2016 22:38:32 -0700 Subject: [PATCH 05/20] Update syntax to match dependencies --- server.js | 2 +- src/App.js | 40 +++++++++++++++++------------------ src/mixins/CommentMixin.js | 8 +++---- src/services/HNService.js | 6 +++--- src/services/HNServiceRest.js | 2 +- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/server.js b/server.js index d163804..3dfd587 100644 --- a/server.js +++ b/server.js @@ -5,7 +5,7 @@ var ReactRouter = require('react-router') var objectAssign = require('object-assign') var HNServerFetch = require('./hn-server-fetch') -require('babel/register') +require('babel-register') var routes = require('./src/routes') var app = express() diff --git a/src/App.js b/src/App.js index ea9e480..56cffa4 100644 --- a/src/App.js +++ b/src/App.js @@ -51,26 +51,26 @@ var App = React.createClass({ render() { return
-
- {' '} - React HN{' '} - new{' | '} - comments {' | '} - show{' | '} - ask{' | '} - jobs - - {this.state.showSettings ? 'hide settings' : 'settings'} - - {this.state.showSettings && } -
-
-
- {this.state.showChildren ? this.props.children : ''} -
- +
+ {' '} + React HN{' '} + new{' | '} + comments {' | '} + show{' | '} + ask{' | '} + jobs + + {this.state.showSettings ? 'hide settings' : 'settings'} + + {this.state.showSettings && } +
+
+
+ {this.state.showChildren ? this.props.children : ''} +
+
} diff --git a/src/mixins/CommentMixin.js b/src/mixins/CommentMixin.js index 9fef5db..e4e66f4 100644 --- a/src/mixins/CommentMixin.js +++ b/src/mixins/CommentMixin.js @@ -86,8 +86,8 @@ var CommentMixin = { {options.collapsible && ' '} [dead] {options.childCounts && ' | (' + options.childCounts.children + ' child' + pluralise(options.childCounts.children, ',ren')} - {options.childCounts && options.childCounts.newComments > 0 && ', '} - {options.childCounts && options.childCounts.newComments > 0 && {options.childCounts.newComments} new} + {options.childCounts && options.childCounts.newComments > 0 && ', '} + {options.childCounts && options.childCounts.newComments > 0 && {options.childCounts.newComments} new} {options.childCounts && ')'}
} @@ -105,8 +105,8 @@ var CommentMixin = { {options.op && {this.state.op.title}} {comment.dead && ' | [dead]'} {options.childCounts && ' | (' + options.childCounts.children + ' child' + pluralise(options.childCounts.children, ',ren')} - {options.childCounts && options.childCounts.newComments > 0 && ', '} - {options.childCounts && options.childCounts.newComments > 0 && {options.childCounts.newComments} new} + {options.childCounts && options.childCounts.newComments > 0 && ', '} + {options.childCounts && options.childCounts.newComments > 0 && {options.childCounts.newComments} new} {options.childCounts && ')'}
}, diff --git a/src/services/HNService.js b/src/services/HNService.js index 6b9b626..54021c2 100644 --- a/src/services/HNService.js +++ b/src/services/HNService.js @@ -1,6 +1,6 @@ -var Firebase = require('firebase') +var firebase = require('firebase') -var api = new Firebase('https://hacker-news.firebaseio.com/v0') +var api = firebase.initializeApp('https://hacker-news.firebaseio.com/v0') function fetchItem(id, cb) { itemRef(id).once('value', function(snapshot) { @@ -44,4 +44,4 @@ module.exports = { itemRef, userRef, updatesRef -} +} \ No newline at end of file diff --git a/src/services/HNServiceRest.js b/src/services/HNServiceRest.js index ef32e17..d73aed5 100644 --- a/src/services/HNServiceRest.js +++ b/src/services/HNServiceRest.js @@ -1,4 +1,4 @@ -/*global fetch*/ +/* global fetch */ require('isomorphic-fetch') /* A version of HNService which concumes the Firebase REST From 70cfa8a1b6e0f72e18a99f21246d45591efe0651 Mon Sep 17 00:00:00 2001 From: Addy Osmani Date: Sun, 2 Oct 2016 22:38:41 -0700 Subject: [PATCH 06/20] Comment out React hash history for now --- src/index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index 0812b31..0447deb 100644 --- a/src/index.js +++ b/src/index.js @@ -1,14 +1,14 @@ require('setimmediate') -var createHashHistory = require('history/lib/createHashHistory') +// var createHashHistory = require('history/lib/createHashHistory') var React = require('react') var {render} = require('react-dom') var Router = require('react-router/lib/Router') -var useRouterHistory = require('react-router/lib/useRouterHistory') -var withScroll = require('scroll-behavior/lib/withStandardScroll') +// var useRouterHistory = require('react-router/lib/useRouterHistory') +// var withScroll = require('scroll-behavior/lib/withStandardScroll') var routes = require('./routes') -var history = withScroll(useRouterHistory(createHashHistory)()) +// var history = withScroll(useRouterHistory(createHashHistory)()) -render(, document.getElementById('app')) +render(, document.getElementById('app')) From e4ee6c3671a4125580ec3ae6cbec563cb8918a9e Mon Sep 17 00:00:00 2001 From: Addy Osmani Date: Wed, 5 Oct 2016 18:09:11 -0700 Subject: [PATCH 07/20] Update dependencies and paths to deps --- package.json | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index e9d3b08..6fb5b21 100644 --- a/package.json +++ b/package.json @@ -9,14 +9,14 @@ "url": "http://github.com/insin/react-hn.git" }, "scripts": { - "build": "npm run lint && cp node_modules/sw-toolbox/sw-toolbox.js public/sw-toolbox.js && ./node_modules/.bin/nwb build && npm run precache", + "build": "npm run lint && cp node_modules/sw-toolbox/sw-toolbox.js dist/sw-toolbox.js && ./node_modules/.bin/nwb build && npm run precache", "deploy": "gcloud preview app deploy", "lint": "./node_modules/eslint-config-jonnybuchanan/bin/lint.js src", "lint:fix": "./node_modules/eslint-config-jonnybuchanan/bin/lint.js --fix .", "start": "node server.js", "postinstall": "npm run build", "serve": "./node_modules/.bin/nwb serve", - "precache": "./node_modules/sw-precache/cli.js --root=public --config=sw-precache-config.json" + "precache": "./node_modules/sw-precache/cli.js --root=dist --config=sw-precache-config.json" }, "engines": { "node": "6.1.0" @@ -46,5 +46,9 @@ "sw-precache": "^4.1.0", "sw-toolbox": "^3.1.1", "url-parse": "^1.1.1" + }, + "devDependencies": { + "html-webpack-plugin": "^2.22.0", + "webpack": "^1.13.2" } -} \ No newline at end of file +} From 52e93813b01c45aa48339e638c8fa1ab39b855ef Mon Sep 17 00:00:00 2001 From: Addy Osmani Date: Wed, 5 Oct 2016 18:10:33 -0700 Subject: [PATCH 08/20] Add HtmlWebpackPlugin for re-wiring up template output --- nwb.config.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/nwb.config.js b/nwb.config.js index 0e2beff..701ffbf 100644 --- a/nwb.config.js +++ b/nwb.config.js @@ -1,3 +1,6 @@ +var HtmlWebpackPlugin = require('html-webpack-plugin') +// var ChunkManifestPlugin = require('chunk-manifest-webpack-plugin') + module.exports = { type: 'react-app', babel: { @@ -16,6 +19,20 @@ module.exports = { define: { __VERSION__: JSON.stringify(require('./package.json').version) } + }, + extra: { + plugins: [ + new HtmlWebpackPlugin({ + filename: 'views/index.ejs', + template: 'src/views/index.ejs', + markup: '<%- markup %>' + }), + new HtmlWebpackPlugin({ + filename: 'index.html', + template: 'public/index-static.html', + markup: '<%- markup %>' + }) + ] } } } \ No newline at end of file From c768de5a47f562cb3919d0fcc468cb432f8e43fc Mon Sep 17 00:00:00 2001 From: Addy Osmani Date: Wed, 5 Oct 2016 18:11:13 -0700 Subject: [PATCH 09/20] Update wiring and EJS templates to include runtime TODO: Figure out how to properly pull in the runtime during builds like this where EJS templates are used --- public/index-static.html | 3 +-- src/views/index.ejs | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/public/index-static.html b/public/index-static.html index d8f94e5..2d651e9 100644 --- a/public/index-static.html +++ b/public/index-static.html @@ -34,8 +34,7 @@
- - + - +
<%- htmlWebpackPlugin.options.markup %>
+ + <%= htmlWebpackPlugin.options.markup %> + -