added ver to qsurvey url

This commit is contained in:
Danny Coates 2017-12-05 12:45:36 -08:00
parent 28a7e0f717
commit 1849d712b1
No known key found for this signature in database
GPG Key ID: 4C442633C62E00CB
3 changed files with 37 additions and 8 deletions

View File

@ -1,5 +1,16 @@
const html = require('choo/html'); const html = require('choo/html');
const assets = require('../../common/assets'); const assets = require('../../common/assets');
/*
The current weback config uses package.json to generate
version.json for /__version__ meaning `require` returns the
string 'version.json' in the frontend context but the json
on the server.
We want `version` to be constant at build time so this file
has a custom loader (/build/version_loader.js) just to replace
string with the value from package.json. 🤢
*/
const version = require('../../package.json').version || 'VERSION';
module.exports = function(state) { module.exports = function(state) {
return html`<header class="header"> return html`<header class="header">
@ -14,8 +25,9 @@ module.exports = function(state) {
<div>${state.translate('siteSubtitle')}</div> <div>${state.translate('siteSubtitle')}</div>
</div> </div>
</div> </div>
<a href="https://qsurvey.mozilla.com/s3/txp-firefox-send" rel="noreferrer noopener" class="feedback" target="_blank">${state.translate( <a href="https://qsurvey.mozilla.com/s3/txp-firefox-send?ver=${version}"
'siteFeedback' rel="noreferrer noopener"
)}</a> class="feedback"
target="_blank">${state.translate('siteFeedback')}</a>
</header>`; </header>`;
}; };

5
build/version_loader.js Normal file
View File

@ -0,0 +1,5 @@
const version = require('../package.json').version;
module.exports = function(source) {
return source.replace('VERSION', version);
};

View File

@ -4,6 +4,12 @@ const CopyPlugin = require('copy-webpack-plugin');
const ManifestPlugin = require('webpack-manifest-plugin'); const ManifestPlugin = require('webpack-manifest-plugin');
const IS_DEV = process.env.NODE_ENV === 'development'; const IS_DEV = process.env.NODE_ENV === 'development';
const regularJSOptions = {
babelrc: false,
presets: [['env', { modules: false }], 'stage-2'],
plugins: ['yo-yoify']
};
module.exports = { module.exports = {
entry: { entry: {
vendor: ['babel-polyfill', 'fluent'], vendor: ['babel-polyfill', 'fluent'],
@ -31,6 +37,16 @@ module.exports = {
} }
] ]
}, },
{
include: require.resolve('./app/templates/header'),
use: [
{
loader: 'babel-loader',
options: regularJSOptions
},
'./build/version_loader'
]
},
{ {
include: [path.dirname(require.resolve('fluent'))], include: [path.dirname(require.resolve('fluent'))],
use: [ use: [
@ -55,11 +71,7 @@ module.exports = {
path.resolve(__dirname, 'node_modules/fluent-intl-polyfill'), path.resolve(__dirname, 'node_modules/fluent-intl-polyfill'),
path.resolve(__dirname, 'node_modules/intl-pluralrules') path.resolve(__dirname, 'node_modules/intl-pluralrules')
], ],
options: { options: regularJSOptions
babelrc: false,
presets: [['env', { modules: false }], 'stage-2'],
plugins: ['yo-yoify']
}
}, },
{ {
include: [path.resolve(__dirname, 'node_modules')], include: [path.resolve(__dirname, 'node_modules')],