From 43e2a588a786ae1ddfa718b0db9b618196bbb4f3 Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Fri, 9 Nov 2018 12:43:45 -0500 Subject: [PATCH 1/2] test --- package.json | 8 ++++---- src/components/app.js | 18 ++++++++--------- src/routes/home/index.js | 7 +++++++ src/routes/license/index.js | 6 ++++++ src/template.html | 40 +++++++++++++++++++++++++++++++++++++ 5 files changed, 66 insertions(+), 13 deletions(-) create mode 100644 src/template.html diff --git a/package.json b/package.json index 0f512aa..4233a79 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,9 @@ "license": "MIT", "scripts": { "start": "if-env NODE_ENV=production && npm run -s serve || npm run -s dev", - "build": "preact build", - "serve": "preact build && preact serve", - "dev": "preact watch", + "build": "preact build --template src/template.html", + "serve": "npm run -s build && preact serve", + "dev": "preact watch --template src/template.html", "lint": "eslint src" }, "eslintConfig": { @@ -30,7 +30,7 @@ "if-env": "^1.0.0", "node-sass": "^4.7.2", "preact-cli": "^2.0.1", - "preact-cli-plugin-async": "^1.0.0", + "preact-cli-plugin-async": "^2.0.0", "preact-cli-plugin-netlify": "^1.1.0", "sass-loader": "^6.0.6", "webpack-critical": "^1.1.1", diff --git a/src/components/app.js b/src/components/app.js index 49cd337..da8a423 100644 --- a/src/components/app.js +++ b/src/components/app.js @@ -48,15 +48,15 @@ class App extends Component { } }; - componentDidMount() { - setTimeout( () => { - import('ganalytics').then( ({ default: GAnalytics }) => { - this.ga = new GAnalytics(config.gaTrackingId); - this.tq.forEach(this.track); - this.tq.length = 0; - }); - }, 250); - } + // componentDidMount() { + // setTimeout( () => { + // import('ganalytics').then( ({ default: GAnalytics }) => { + // this.ga = new GAnalytics(config.gaTrackingId); + // this.tq.forEach(this.track); + // this.tq.length = 0; + // }); + // }, 250); + // } render({ url }) { return ( diff --git a/src/routes/home/index.js b/src/routes/home/index.js index 8253300..49a4e10 100644 --- a/src/routes/home/index.js +++ b/src/routes/home/index.js @@ -15,11 +15,18 @@ function flattenAliases(data, item) { const getName = obj => obj.name || obj.key; +let first = true; + @wire('model', { licenses: 'getAllLicenses' }, ({ getAllLicensesSync }) => ({ getAllLicensesSync })) export default class Home extends Component { render({ licenses, pending, getAllLicensesSync }) { + if (licenses && first) { + first = false; + window.ga('send', 'timing', 'content', 'load', Math.round(performance.now())); + } + // prerendering! if (!licenses || pending && pending.licenses) licenses = getAllLicensesSync ? getAllLicensesSync() : window.ALL_LICENSES; diff --git a/src/routes/license/index.js b/src/routes/license/index.js index 7761c57..887792b 100644 --- a/src/routes/license/index.js +++ b/src/routes/license/index.js @@ -24,6 +24,7 @@ function getQuery(matches, githubProfile) { return query; } +let first = true; @wire('model', ({ licenseId, gh }) => ({ license: licenseId && ['getLicense', licenseId], @@ -76,6 +77,11 @@ export default class License extends Component { render({ licenseId, license, pending, error, matches, githubProfile }) { let query = getQuery(matches, githubProfile); + if (license && first) { + first = false; + window.ga('send', 'timing', 'content', 'load', Math.round(performance.now())); + } + return (
diff --git a/src/template.html b/src/template.html new file mode 100644 index 0000000..80234cb --- /dev/null +++ b/src/template.html @@ -0,0 +1,40 @@ + + + + + <%= htmlWebpackPlugin.options.title %> + + + + + <% if (htmlWebpackPlugin.options.manifest.theme_color) { %> + + <% } %> + + <% for (var chunk of webpack.chunks) { %> + <% if (chunk.names.length === 1 && chunk.names[0] === 'polyfills') continue; %> + <% for (var file of chunk.files) { %> + <% if (htmlWebpackPlugin.options.preload && file.match(/\.(js|css)$/)) { %> + + <% } else if (file.match(/manifest\.json$/)) { %> + + <% } %> + <% } %> + <% } %> + + + <%= htmlWebpackPlugin.options.ssr({ + url: '/' + }) %> + + + + \ No newline at end of file From 56d02b37a87c00443863db265f7bc9fc2f174fd9 Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Fri, 9 Nov 2018 12:46:51 -0500 Subject: [PATCH 2/2] test 2