Created
September 26, 2015 16:18
-
-
Save Morgul/297dcab9bf486cae4bbc to your computer and use it in GitHub Desktop.
Vuejs Component Template loader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//---------------------------------------------------------------------------------------------------------------------- | |
/// A simple template loader for Vue components (browserify or electron app) | |
/// | |
/// @module | |
//---------------------------------------------------------------------------------------------------------------------- | |
var fs = require('fs'); | |
var path = require('path'); | |
var Vue = require('../vendor/vue/dist/vue'); | |
//---------------------------------------------------------------------------------------------------------------------- | |
var rootPath = path.resolve(__dirname, '..', 'dist'); | |
function loadAsync(componentName, vueOpts) | |
{ | |
return Vue.component(componentName, function(resolve, reject) | |
{ | |
if(vueOpts.templateUrl) | |
{ | |
fs.readFile(path.join(rootPath, vueOpts.templateUrl), 'utf8', function(error, html) | |
{ | |
if(error) | |
{ | |
reject(error); | |
} | |
else | |
{ | |
delete vueOpts.templateUrl; | |
vueOpts.template = html; | |
resolve(vueOpts); | |
} // end if | |
}); | |
} | |
else | |
{ | |
resolve(vueOpts); | |
} // end if | |
}); | |
} // end loadAsync | |
//---------------------------------------------------------------------------------------------------------------------- | |
module.exports = { loadAsync: loadAsync }; | |
//---------------------------------------------------------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment