# json-templater/string
插件
TIP
json-templater
可以在js和json对象上进行胡子样式模板替换
- 先搭建环境
$ npm init -y && npm i -D webpack webpack-cli json-template && touch index.js
1
- index.js 文件内容:
const render = require('json-templater/string');
const IMPORT_TEMPLATE = 'import {{name}} from \'../packages/{{package}}/index.js\';';
parseStrTemplate = render(IMPORT_TEMPLATE, {name: 'input', package: 'input'});
console.log('-----------------------------------------------------');
console.log(parseStrTemplate);
console.log('-----------------------------------------------------');
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
- 执行
node index.js
输出:
-----------------------------------------------------
import input from '../packages/input/index.js';
-----------------------------------------------------
1
2
3
2
3
WARNING