3.1.4 • Published 6 months ago
templatejs-loader v3.1.4
template-loader
template.js的 webpack 编译 loader,同时支持在 rspack 使用。
安装
$ npm install --save @templatejs/runtime # 安装template运行时
$ npm install --save-dev templatejs-loader # 安装template编译插件
webpack 配置
配置参数同template.js参数一样,其中 expression 参数会作为获取 template 的表达式。
webpack 4-5,在 webpack.config.js 配置文件中增加如下内容:
module.exports = {
module: {
rules: [
{
test: /\.tmpl/,
use: [
{
loader: 'templatejs-loader',
options: {
sTag: '<%',
eTag: '%>',
expression: 'require("@templatejs/runtime").default',
},
},
],
},
],
},
};
webpack 1-3,在 webpack.config.js 配置文件中增加如下内容:
loaders: [
{
test: /\.tmpl/,
loader: 'templatejs-loader',
query: {
sTag: '<#',
eTag: '#>',
sandbox: false, // 沙箱模式
expression: 'require("@templatejs/runtime").default', // webpack 2-4
// expression: 'require("@templatejs/runtime")' // webpack 1
},
},
];
新建模版文件 demo.tmpl
<div>
<#=abc#>
</div>
在 js 中require
模版文件,并渲染
var tpl = require('./demo.tmpl');
document.getElementById('test').innerHTML = tpl({ abc: 'yanhaijing' });
rspack 配置
配置参数同template.js参数一样,其中 expression 参数会作为获取 template 的表达式。
在 rspack.config.js 配置文件中增加如下内容:
module.exports = {
module: {
rules: [
{
test: /\.tmpl/,
use: [
{
loader: 'templatejs-loader',
options: {
sTag: '<%',
eTag: '%>',
expression: 'require("@templatejs/runtime").default',
},
},
],
},
],
},
};
新建模版文件 demo.tmpl
<div>
<#=abc#>
</div>
在 js 中require
模版文件,并渲染
var tpl = require('./demo.tmpl');
document.getElementById('test').innerHTML = tpl({ abc: 'yanhaijing' });
贡献者列表
:gear: 更新日志
:airplane: 计划列表
相关链接
3.1.2-alpha.0
6 months ago
3.1.4
6 months ago
3.1.3-alpha.0
6 months ago
3.0.0-alpha.0
6 months ago
3.1.1-alpha.0
6 months ago
3.1.0-alpha.0
6 months ago
2.7.0
8 months ago
2.6.0
8 months ago
2.4.2
4 years ago
2.4.1
4 years ago
2.4.0
4 years ago
2.3.0
4 years ago
2.2.1
4 years ago
2.2.0
4 years ago
2.1.0
4 years ago
2.0.2
5 years ago
2.0.2-alpha.0
5 years ago
0.1.1
7 years ago
0.1.0
7 years ago