sl

string-loader

webpack loader: resource file transform to string

Showing:

Popularity

Downloads/wk

1K

GitHub Stars

9

Maintenance

Last Commit

5yrs ago

Contributors

0

Package

Dependencies

0

Size (min+gzip)

0.2KB

License

ISC

Type Definitions

Tree-Shakeable

No?

Categories

Readme

string loader for webpack

webpack loader: resource file transform to string

Installation

npm install string-loader --save-dev

Usage

webpack.config setting

loaders: [ { test: /\.[name]$/, loader: "string" } ]

Example 1: html transform to string template

webpack.config

loaders: [ { test: /\.html$/, loader: "string" } ]

list.tpl.html

<ul>
    <% for(var i in list){ %>
        <li><%= list[i].text %></li>
    <% } %>
</ul>

list.js

var Template = require('template'),
    TPL = require('./list.tpl.html');

var html = Template(TPL, [
    {
        text: 'option1'
    },
    {
        text: 'option2'
    }
]);

console.log(html);  //html: '<ul><li>option1</li><li>option2</li></ul>'

Example 2: josn transform to string template

webpack.config

loaders: [ { test: /\.html|\.json$/, loader: "string" } ]

data.json

[
  {
    "text": "first",
    "value": "first"
  },
  {
    "text": "second",
    "value": "second"
  }
]

index.js

var str = require('./data');

var json = JSON.parse(str);

console.log(json);  //json: [{"text": "first","value": "first"},{"text": "second","value": "second"}]

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial