isv-xtemplate-loader
v10.0.9
Published
xtemplate loader for webpack
Downloads
6
Maintainers
Readme
xtemplate-loader for webpack
xtemplate loader for webpack. Uses xtemplate function to compile templates.
Installation
npm install @ali/xtemplate-loader
Usage 1
./index.xtpl
{{var}} 我编译好了!!!
var template = require("@ali/xtemplate-loader!./index.xtpl");
// => returns the template function compiled with xtemplate templating engine.
var data = {var : "啊"};
var html = template(data);
console.log(html);// => 啊 我编译好了!!!
Usage 2
Config example:
module.exports = {
module: {
loaders: [
{ test: /\.xtpl$/, loader: "@ali/xtemplate-loader" },
]
},
resolveLoader: {
root: path.join(__dirname, "node_modules")
}
};
common usage
var xtpl = require("./index.xtpl");
var data = {var : "啊"};
var html = xtpl(data);
console.log(html);// => 啊 我编译好了!!!
other syntax
./index.xtpl
{{var}} 我{{testc(5)}}编译好了!!!
var xtpl = require("./index.xtpl");
var data = {var : "啊"};
var html = xtpl(data, {
commands : {
"testc" : function(scope, option){
var n = option.params[0];
return n + 1;
}
}
}););
console.log(html);// => 啊 我6编译好了!!!
ps
问:怎么保证用户使用的runtime版本和工具使用的xtemplate版本一致呢? 答:工具自动保证,类似handbar-runtime处理方案。
License
MIT (http://www.opensource.org/licenses/mit-license.php)