1、安装依赖
yarn add art-template art-template-loader
2、在webpack配置文件(比如webpack.common.js)中增加
module.exports = {
module: {
rules: [
{
test: /\.art$/,
loader: 'art-template-loader'
}
]
}
}
3、使用
// index.main.js
const render = require('./index.art');
const data = {
title: 'My Page',
msg: '模板测试信息'
};
const html = render(data);
<!-- index.art -->
{{include './header.art'}}
<h2>Hello art-template!!!</h2>
<h3>{{msg}}</h3>
<img class="testImg" src="./image.jpg">
<!-- header.art -->
<h1>{{title}}</h1>