Fix production webpack build
This commit is contained in:
@ -121,7 +121,7 @@
|
||||
"babel-preset-react": "^6.3.13",
|
||||
"babel-preset-stage-0": "^6.3.13",
|
||||
"browser-sync": "^2.9.12",
|
||||
"chunk-manifest-webpack-plugin": "0.0.1",
|
||||
"chunk-manifest-webpack-plugin": "0.1.0",
|
||||
"del": "^2.2.0",
|
||||
"eslint": "^3.1.0",
|
||||
"eslint-plugin-react": "^5.1.1",
|
||||
|
@ -1,15 +0,0 @@
|
||||
export default function globalLocals() {
|
||||
return function(req, res, next) {
|
||||
// Make user object available in templates.
|
||||
res.locals.user = req.user;
|
||||
res.locals._csrf = req.csrfToken ? req.csrfToken() : null;
|
||||
if (req.csrfToken) {
|
||||
res.expose({ token: res.locals._csrf }, 'csrf');
|
||||
}
|
||||
res.locals.theme = req.user && req.user.theme ||
|
||||
req.cookies.theme ||
|
||||
'default';
|
||||
|
||||
next();
|
||||
};
|
||||
}
|
@ -1,20 +1,54 @@
|
||||
const challengesRegex = /^(bonfire|waypoint|zipline|basejump|checkpoint):\s/i;
|
||||
import manifest from '../rev-manifest';
|
||||
import config from '../../webpack.config';
|
||||
|
||||
let chunkManifest;
|
||||
try {
|
||||
chunkManifest = require('../manifests/chunk-manifest.json');
|
||||
} catch (err) {
|
||||
chunkManifest = {};
|
||||
}
|
||||
|
||||
chunkManifest = Object.keys(chunkManifest).reduce((manifest, key) => {
|
||||
manifest[key] = '/' + chunkManifest[key];
|
||||
return manifest;
|
||||
}, {});
|
||||
|
||||
const __DEV__ = process.env.NODE_ENV !== 'production';
|
||||
const challengesRegex = /^(bonfire|waypoint|zipline|basejump|checkpoint):\s/i;
|
||||
|
||||
function rev(scopedPrepend, asset) {
|
||||
if (__DEV__) {
|
||||
// do not use revision in dev mode
|
||||
return `${scopedPrepend}/${asset}`;
|
||||
}
|
||||
return `${scopedPrepend}/${ manifest[asset] || asset }`;
|
||||
}
|
||||
|
||||
function removeOldTerms(str = '') {
|
||||
return str.replace(challengesRegex, '');
|
||||
}
|
||||
|
||||
function getBundleLocation() {
|
||||
return __DEV__ ?
|
||||
config.output.publicPath + '/bundle.js' :
|
||||
rev('/js', 'bundle.js');
|
||||
}
|
||||
|
||||
export default function jadeHelpers() {
|
||||
return function jadeHelpersMiddleware(req, res, next) {
|
||||
res.locals.removeOldTerms = function removeOldTerms(str = '') {
|
||||
return str.replace(challengesRegex, '');
|
||||
};
|
||||
|
||||
res.locals.getBundleLocation = function getBundleLocation() {
|
||||
return __DEV__ ?
|
||||
config.output.publicPath + '/bundle.js' :
|
||||
'js/bundle.js';
|
||||
};
|
||||
|
||||
res.locals.removeOldTerms = removeOldTerms;
|
||||
res.locals.getBundleLocation = getBundleLocation;
|
||||
res.locals.rev = rev;
|
||||
// static data
|
||||
res.locals.user = req.user;
|
||||
res.locals.chunkManifest = chunkManifest;
|
||||
res.locals._csrf = req.csrfToken ? req.csrfToken() : null;
|
||||
if (req.csrfToken) {
|
||||
res.expose({ token: res.locals._csrf }, 'csrf');
|
||||
}
|
||||
res.locals.theme = req.user && req.user.theme ||
|
||||
req.cookies.theme ||
|
||||
'default';
|
||||
next();
|
||||
};
|
||||
}
|
||||
|
@ -1,19 +0,0 @@
|
||||
import manifest from '../rev-manifest.json';
|
||||
|
||||
const __DEV__ = process.env.NODE_ENV === 'development';
|
||||
|
||||
export default function({ globalPrepend = '' } = {}) {
|
||||
|
||||
function rev(scopedPrepend, asset) {
|
||||
if (__DEV__) {
|
||||
// do not use revision in dev mode
|
||||
return `${globalPrepend}${scopedPrepend}/${asset}`;
|
||||
}
|
||||
return `${globalPrepend}${scopedPrepend}/${ manifest[asset] || asset }`;
|
||||
}
|
||||
|
||||
return function(req, res, next) {
|
||||
res.locals.rev = rev;
|
||||
return next();
|
||||
};
|
||||
}
|
@ -9,5 +9,7 @@ html(lang='en')
|
||||
body.no-top-and-bottom-margins(style='overflow: hidden')
|
||||
#fcc!= markup
|
||||
script!= state
|
||||
script.
|
||||
window.webpackManifest = !{JSON.stringify(chunkManifest || {})};
|
||||
script(src=rev('/js', 'vendor-challenges.js'))
|
||||
script(src=getBundleLocation())
|
||||
|
Reference in New Issue
Block a user