Inject underscore template file into main html file inside script tag.
npm install node-inject-template
node ./node_modules/node-inject-template/index.js dest=index.html folder=templates
That command take two options :
- dest : destination file whete templates content will be injected
- folder : folder who containes all templates to inject
In this case all files in templates folder will be injected in index.html file.
Before run command you must add that html comment in destination file :
<!-- #! template -->
<!-- ## template -->
index.html file :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
</head>
<body>
<!-- #! template -->
<!-- ## template -->
</body>
</html>
A templates file in templates folder, main-view.html
<h1>
<% _.first(['hello']) %> world
</h1>
Result after command (output file is actually not prettyfied) :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
</head>
<body>
<!-- #! template -->
<script type="text/template" id="template-1">
<h1>
<% _.first(['hello']) %> world
</h1>
</script>
<!-- ## template -->
</body>
</html>
- Create grunt plugin
- Add possibility to run command without node ./node_modules/node-inject-template/index.js
- Reset destination file before inject template