From 87cc69947d0004a4d0ae8a7110f2f0751ae7f910 Mon Sep 17 00:00:00 2001 From: Eliot Berriot <contact@eliotberriot.com> Date: Sun, 31 Mar 2019 13:32:44 +0200 Subject: [PATCH] Added preprendering for all pages/locales --- .gitlab-ci.yml | 3 ++- scripts/i18n-compile.sh | 2 +- scripts/i18n-extract.sh | 2 +- src/locales.js | 2 +- vue.config.js | 46 ++++++++++++++++++++++++----------------- 5 files changed, 32 insertions(+), 23 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 176be893..c19ed40d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,10 +4,11 @@ stages: pages: stage: build - image: funkwhale/front-base + image: buildkite/puppeteer variables: GIT_STRATEGY: clone before_script: + - apt-get update && apt-get install -y jq - yarn install script: - yarn lint diff --git a/scripts/i18n-compile.sh b/scripts/i18n-compile.sh index 17d9653b..1b9d2c6f 100755 --- a/scripts/i18n-compile.sh +++ b/scripts/i18n-compile.sh @@ -1,5 +1,5 @@ #!/bin/bash -eux -locales=$(tail -n +2 src/locales.js | sed -e 's/export default //' | jq '.locales[].code' | xargs echo) +locales=$(tail -n +2 src/locales.js | sed -e 's/module.exports = //' | jq '.locales[].code' | xargs echo) mkdir -p src/translations for locale in $locales; do diff --git a/scripts/i18n-extract.sh b/scripts/i18n-extract.sh index a07b21f6..c901253c 100755 --- a/scripts/i18n-extract.sh +++ b/scripts/i18n-extract.sh @@ -1,5 +1,5 @@ #!/bin/bash -eux -locales=$(tail -n +2 src/locales.js | sed -e 's/export default //' | jq '.locales[].code' | xargs echo) +locales=$(tail -n +2 src/locales.js | sed -e 's/module.exports = //' | jq '.locales[].code' | xargs echo) locales_dir="locales" sources=$(find src -name '*.vue' -o -name '*.html' 2> /dev/null) js_sources=$(find src -name '*.vue' -o -name '*.js') diff --git a/src/locales.js b/src/locales.js index 1253354c..511713a1 100644 --- a/src/locales.js +++ b/src/locales.js @@ -1,5 +1,5 @@ /* eslint-disable */ -export default { +module.exports = { "locales": [ { "code": "en_US", diff --git a/vue.config.js b/vue.config.js index 8951cae4..5184b1f2 100644 --- a/vue.config.js +++ b/vue.config.js @@ -1,22 +1,30 @@ -// locales = required('src/locales') -// const path = require("path"); -// const PrerenderSPAPlugin = require("prerender-spa-plugin"); +const locales = require("./src/locales"); +const path = require("path"); +const PrerenderSPAPlugin = require("prerender-spa-plugin"); module.exports = { - // configureWebpack: config => { - // if (process.env.NODE_ENV !== 'production') return - // return { - // plugins: [ - // new PrerenderSPAPlugin( - // // Absolute path to compiled SPA - // path.resolve(__dirname, 'dist'), - // // List of routes to prerender - // [ '/', '/code-of-conduct', '/community'], - // { - // // options - // } - // ), - // ] - // } - // } + configureWebpack: config => { + if (process.env.NODE_ENV !== "production") return; + let baseRoutes = ["/", "/code-of-conduct", "/community", "/contact"]; + let finalRoutes = []; + baseRoutes.forEach(p => { + finalRoutes.push(p); + locales.locales.forEach(l => { + finalRoutes.push("/" + l.code + p); + }); + }); + return { + plugins: [ + new PrerenderSPAPlugin( + // Absolute path to compiled SPA + path.resolve(__dirname, "dist"), + // List of routes to prerender + finalRoutes, + { + // options + } + ) + ] + }; + } }; -- GitLab