项目作者: d-band

项目描述 :
Ejs template loader using babel.
高级语言: JavaScript
项目地址: git://github.com/d-band/etpl-loader.git
创建时间: 2018-11-02T17:13:44Z
项目社区:https://github.com/d-band/etpl-loader

开源协议:

下载


etpl-loader

NPM version
NPM downloads
Build Status
Coverage Status
Dependency Status

Install

  1. npm i etpl-loader -S

Usage

index.tpl

  1. <p><%=name%></p>
  2. <p><%=email%></p>
  3. <ul>
  4. <%for (var i=0; i<skills.length; i++) {var skill = skills[i];%>
  5. <li><%-skill%></li>
  6. <%}%>
  7. </ul>
  8. <div>
  9. <%projects.forEach((project) => {%>
  10. <div>
  11. <h3><%-project.name%></h3>
  12. <p><%=project.description%></p>
  13. </div>
  14. <%});%>
  15. </div>
  16. <%include('footer.tpl')%>

footer.tpl

  1. <div>Copyright © <%=site.year%> <%=site.name%>. All Rights Reserved.</div>

index.js

  1. import tpl from './index.tpl';
  2. window.ENCODE = (str) => {
  3. return String(str)
  4. .replace(/&/g, '&')
  5. .replace(/"/g, '"')
  6. .replace(/'/g, ''')
  7. .replace(/</g, '<')
  8. .replace(/>/g, '>');
  9. };
  10. document.getElementById('root').innerHTML = tpl({
  11. name: 'hello',
  12. email: 'hello@example.com',
  13. skills: [
  14. '<a href="https://en.wikipedia.org/wiki/JavaScript">JavaScript</a>',
  15. '<a href="https://www.oracle.com/java/">Java</a>',
  16. '<a href="https://en.wikipedia.org/wiki/C%2B%2B">C++</a>',
  17. '<a href="https://golang.org">Go</a>'
  18. ],
  19. projects: [{
  20. name: '<a href="https://github.com/d-band/etpl-loader">etpl-loader</a>',
  21. description: 'Ejs template webpack loader.'
  22. }, {
  23. name: '<a href="https://github.com/d-band/dool">dool</a>',
  24. description: 'Build tool based on webpack.'
  25. }, {
  26. name: '<a href="https://github.com/d-band/yax">yax</a>',
  27. description: 'Yet another store using redux.'
  28. }],
  29. site: {
  30. name: 'D-Band',
  31. year: '2018'
  32. }
  33. });

webpack.config.js

  1. module.exports = {
  2. module: {
  3. rules: [{
  4. test: /\.tpl$/,
  5. use: 'etpl-loader'
  6. }]
  7. }
  8. }

Options

Name Type Default Description
globals {Array} ['window', 'console'] Global variables
encode {String} 'ENCODE' Encode function name

Report a issue

License

etpl-loader is available under the terms of the MIT License.