Further improvements to page prerendering

This commit is contained in:
Jeff Avallone 2018-02-13 17:28:47 -05:00
parent 44a9cad9b3
commit 94e511bb96
4 changed files with 19 additions and 9 deletions

3
src/pages/404/config.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = {
title: 'Regexper - Page Not Found'
};

View File

@ -0,0 +1,3 @@
module.exports = {
title: 'Regexper'
};

View File

@ -3,13 +3,13 @@
<head> <head>
<meta charSet="utf-8" /> <meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="description" content={ pkg.description } /> <meta name="description" content="<%= htmlWebpackPlugin.options.description %>" />
<link rel="author" href="/humans.txt" /> <link rel="author" href="/humans.txt" />
<title>Regexper</title> <title><%= htmlWebpackPlugin.options.title %></title>
</head> </head>
<body data-build-id="<%= process.env.BUILD_ID %>"> <body data-build-id="<%= htmlWebpackPlugin.options.buildId %>">
<div id="root"></div> <div id="root"></div>
</body> </body>
</html> </html>

View File

@ -7,9 +7,16 @@ const FaviconsPlugin = require('favicons-webpack-plugin-cesco');
const HtmlPlugin = require('html-webpack-plugin'); const HtmlPlugin = require('html-webpack-plugin');
const pkg = require('./package.json'); const pkg = require('./package.json');
const buildId = [
process.env.CIRCLE_BRANCH || 'prerelease',
process.env.CIRCLE_BUILD_NUM || '##',
(process.env.CIRCLE_SHA1 || 'gitsha').slice(0, 7)
].join('-');
const pages = fs.readdirSync(path.resolve(__dirname, 'src/pages')); const pages = fs.readdirSync(path.resolve(__dirname, 'src/pages'));
const pagePlugins = pages.map(name => new HtmlPlugin({ const pagePlugins = pages.map(name => new HtmlPlugin({
description: pkg.description,
buildId,
template: './src/template.html', template: './src/template.html',
filename: `${ name }.html`, filename: `${ name }.html`,
chunks: ['common', name], chunks: ['common', name],
@ -23,7 +30,8 @@ const pagePlugins = pages.map(name => new HtmlPlugin({
minifyJS: true, minifyJS: true,
minifyCSS: true, minifyCSS: true,
minifyURLs: true minifyURLs: true
} },
...require(`./src/pages/${ name }/config`)
})); }));
module.exports = { module.exports = {
@ -42,11 +50,7 @@ module.exports = {
GA_PROPERTY: null, GA_PROPERTY: null,
SENTRY_KEY: null, SENTRY_KEY: null,
BANNER: process.env.NODE_ENV === 'production' ? null : (process.env.NODE_ENV || 'development'), BANNER: process.env.NODE_ENV === 'production' ? null : (process.env.NODE_ENV || 'development'),
BUILD_ID: [ BUILD_ID: buildId
process.env.CIRCLE_BRANCH || 'prerelease',
process.env.CIRCLE_BUILD_NUM || '##',
(process.env.CIRCLE_SHA1 || 'gitsha').slice(0, 7)
].join('-')
}), }),
new webpack.optimize.CommonsChunkPlugin({ new webpack.optimize.CommonsChunkPlugin({
name: 'common', name: 'common',