mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
FIxes #188 - Performance: Assume *.marko.js files are up-to-date in production
This commit is contained in:
parent
15c837f45d
commit
cf53fe02c9
@ -17,6 +17,7 @@
|
||||
var extend = require('raptor-util/extend');
|
||||
var req = require; // Fool code inspectors used by client-side bundles
|
||||
var nodePath = require('path');
|
||||
var NODE_ENV = process.env.NODE_ENV;
|
||||
|
||||
var defaultOptions = {
|
||||
/**
|
||||
@ -62,7 +63,12 @@ var defaultOptions = {
|
||||
* compiled templates will not be written to disk (i.e., no `.marko.js` file will
|
||||
* be generated)
|
||||
*/
|
||||
writeToDisk: true
|
||||
writeToDisk: true,
|
||||
|
||||
/**
|
||||
* If true, then the compiled template on disk will assumed to be up-to-date if it exists.
|
||||
*/
|
||||
assumeUpToDate: NODE_ENV == null ? false : (NODE_ENV !== 'development' && NODE_ENV !== 'dev')
|
||||
};
|
||||
|
||||
if (process.env.MARKO_CLEAN === '' || process.env.MARKO_CLEAN === 'true') {
|
||||
|
||||
@ -45,12 +45,36 @@ function loadSource(templatePath, compiledSrc) {
|
||||
}
|
||||
|
||||
function loadFile(templatePath, options) {
|
||||
var targetFile = templatePath + '.js';
|
||||
|
||||
// Short-circuit loading if the template has already been cached in the Node.js require cache
|
||||
var cached = require.cache[targetFile];
|
||||
if (cached) {
|
||||
return cached.exports;
|
||||
}
|
||||
|
||||
templatePath = nodePath.resolve(cwd, templatePath);
|
||||
var targetDir = nodePath.dirname(templatePath);
|
||||
|
||||
var targetFile = templatePath + '.js';
|
||||
targetFile = templatePath + '.js';
|
||||
|
||||
// Check the require cache again after fully resolving the path
|
||||
cached = require.cache[targetFile];
|
||||
if (cached) {
|
||||
return cached.exports;
|
||||
}
|
||||
|
||||
// If the `assumeUpToDate` option is true then we just assume that the compiled template on disk is up-to-date
|
||||
// if it exists
|
||||
if (markoCompiler.defaultOptions.assumeUpToDate) {
|
||||
if (fs.existsSync(targetFile)) {
|
||||
return require(targetFile);
|
||||
}
|
||||
}
|
||||
|
||||
var compiler = markoCompiler.createCompiler(templatePath, options);
|
||||
var isUpToDate = compiler.checkUpToDate(targetFile);
|
||||
|
||||
if (isUpToDate) {
|
||||
return require(targetFile);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user