From f15f9f3e381750bafa07dfe11658f7f91e519754 Mon Sep 17 00:00:00 2001 From: Arunoda Susiripala Date: Thu, 12 Jan 2017 00:45:21 +0530 Subject: [PATCH 1/5] Write BUILD_ID when building. It's a random id (uuid.v4()) --- package.json | 1 + server/build/index.js | 10 ++++++++++ yarn.lock | 8 ++++---- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 7df095c8ad063..99bd6cb985d6a 100644 --- a/package.json +++ b/package.json @@ -76,6 +76,7 @@ "strip-ansi": "3.0.1", "styled-jsx": "0.4.1", "url": "0.11.0", + "uuid": "3.0.1", "webpack": "2.2.0-rc.3", "webpack-dev-middleware": "1.9.0", "webpack-hot-middleware": "2.15.0", diff --git a/server/build/index.js b/server/build/index.js index e4fcb84574c05..482626deefef2 100644 --- a/server/build/index.js +++ b/server/build/index.js @@ -1,3 +1,6 @@ +import fs from 'mz/fs' +import uuid from 'uuid' +import path from 'path' import webpack from './webpack' import clean from './clean' import gzipAssets from './gzip' @@ -10,6 +13,7 @@ export default async function build (dir) { await runCompiler(compiler) await gzipAssets(dir) + await writeBuildId(dir) } function runCompiler (compiler) { @@ -29,3 +33,9 @@ function runCompiler (compiler) { }) }) } + +async function writeBuildId (dir) { + const buildIdPath = path.resolve(dir, '.next', 'BUILD_ID') + const buildId = uuid.v4() + await fs.writeFile(buildIdPath, buildId, 'utf8') +} diff --git a/yarn.lock b/yarn.lock index cb9f70c0e007b..932d774ee79a3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -733,9 +733,9 @@ babel-plugin-transform-strict-mode@^6.18.0: babel-runtime "^6.0.0" babel-types "^6.18.0" -babel-preset-env@1.1.6: - version "1.1.6" - resolved "https://registry.yarnpkg.com/babel-preset-env/-/babel-preset-env-1.1.6.tgz#83ce1402088e661cb5799e680d20c5a432b2873b" +babel-preset-env@1.1.8: + version "1.1.8" + resolved "https://registry.yarnpkg.com/babel-preset-env/-/babel-preset-env-1.1.8.tgz#c46734c6233c3f87d177513773db3cf3c1758aaa" dependencies: babel-plugin-check-es2015-constants "^6.3.13" babel-plugin-syntax-trailing-function-commas "^6.13.0" @@ -5028,7 +5028,7 @@ util@^0.10.3, util@0.10.3: dependencies: inherits "2.0.1" -uuid@^3.0.0: +uuid, uuid@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.0.1.tgz#6544bba2dfda8c1cf17e629a3a305e2bb1fee6c1" From 43c838df805f7713bdf70ff05e7f1cb35d28fa6d Mon Sep 17 00:00:00 2001 From: Arunoda Susiripala Date: Thu, 12 Jan 2017 01:03:35 +0530 Subject: [PATCH 2/5] Add buildId to the core JS files. --- server/document.js | 19 ++++++++++++++----- server/index.js | 17 +++++++++++++++++ server/render.js | 2 ++ 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/server/document.js b/server/document.js index 49f75272251d2..5e4c552d27379 100644 --- a/server/document.js +++ b/server/document.js @@ -85,11 +85,20 @@ export class NextScript extends Component { } render () { - const { staticMarkup } = this.context._documentProps + const { staticMarkup, __NEXT_DATA__ } = this.context._documentProps + const { buildId } = __NEXT_DATA__ - return
- { staticMarkup ? null :