template-importing-loader

0.0.1 • Public • Published

template-importing-loader

====================

webpack loader, adding <import> syntax for javascript templates (underscore template engine, etc)

usage

npm install template-importing-loader --save-dev

it's better used with template2module-loader

{
  module: {
    loaders: [
      {
        test: /\.tpl$/,
        loader: 'template2module-loader',
        query: {
          engine: 'underscore',
          format: 'commonjs',
          outerScopeVars: [
            'translate',
            '_',
          ],
          preOuterScope: [
            'var translate = require("zero-text/i18n").translate;',
            'var _ = require("underscore");',
          ].join('\n'),
        }
      }
    ],
 
    // resolving template importing before transform files to `template2module-loader`
    preLoaders: [
      {
        test: /\.tpl$/,
        loader: 'template-importing-loader'
      }
    ]
  }
}

template files

src
   |--greeting.tpl
   |--comman.tpl

src/greeting.tpl

I am <%=name%><%if(man){%> and I like playing <%=man.game%><%}%>.
My favorite animates are
<% _.each(animates, function(animate){ %>
   <% if (animate.type !== invisibleType ){ %>
       <%=animate.name%>
   <% } %>
<% }); %>
etc.
 
<import src="./common.tpl"></import>

src/common.tpl

hello, template importing.

when src/greeting.tpl is passed to other loaders, it's content is like:

I am <%=name%><%if(man){%> and I like playing <%=man.game%><%}%>.
My favorite animates are
<% _.each(animates, function(animate){ %>
   <% if (animate.type !== invisibleType ){ %>
       <%=animate.name%>
   <% } %>
<% }); %>
etc.
 
hello, template importing.

Package Sidebar

Install

npm i template-importing-loader

Weekly Downloads

2

Version

0.0.1

License

MIT

Last publish

Collaborators

  • leungwensen