Authored by yyq

manifest

... ... @@ -30,8 +30,20 @@ const stringProcess = require('./utils/string-process');
const app = express();
// 向模板注入变量
global.devEnv = app.locals.devEnv = app.get('env') === 'development';
global.isProduction = app.locals.isProduction = app.get('env') === 'production';
switch (app.get('env')) {
case 'development':
global.devEnv = app.locals.devEnv = true;
break;
case 'test':
global.isTest = app.locals.isTest = true;
break;
case 'production':
global.isProduction = app.locals.isProduction = true;
break;
default:
break;
}
global.version = app.locals.version = pkg.version;
app.locals.startTime = moment().format('YYYYMMDDHH');
app.locals.currentYear = moment().format('YYYY');
... ...
... ... @@ -5,8 +5,15 @@ module.exports = (app) => {
let manifest;
if (!app.locals.devEnv) {
manifest = require('../../manifest.json');
let manifestPath = '../../manifest.json';
if (app.locals.isTest) {
manifestPath = `../../dist/statics/${config.appName}/${app.locals.version}/manifest.json`;
}
manifest = require(manifestPath);
}
function getStatic(path, def) {
return _.get(manifest, path, `${config.assetUrl}${def}`);
}
... ...