1.2.2 • Published 3 years ago

inline-resource-literal v1.2.2

Weekly downloads
76
License
LGPL
Repository
github
Last release
3 years ago

InlineResourceLiteral

NPM Version

InlineResource is a Javascript build tool that handles inlining of common types of resources with a declarative syntax. It provides an ability to replace pre-defined placeholders into JS expressions at build time. It automatically minifies files with extension html and css.

Installation

Add InlineResource to your project's devDependency by executing:

yarn add inline-resource-literal --dev

Usage

Sources

// source.js
...
element.innerHTML = RESOURCE_TEMPLATE;
...
// template.html
<html><div></div></html>

Build setup

Using CLI

inline-resc source.js inlined.js --resc:TEMPLATE template.html

Using JS API

// build.js
const InlineResource = require("inline-resource-literal");
const fs = require('fs');

const file = fs.readFileSync('./source.js').toString();

const inlined = (new InlineResource({
    "TEMPLATE": './template.html'
})).inline(file);

fs.writeFileSync('./inlined.js', inlined);

Output

// inlined.js
element.innerHTML = "<div></div>";

Inlining with Precomputed Values

Sources

// source.js
element.innerHTML = RESOURCE_ARGS("TEMPLATE", "DOMAIN", document.domain, "LANGUAGE", navigator.language);
// template.html
<p>domain is: RESOURCE_DOMAIN</p>
<p>language is: RESOURCE_LANGUAGE</p>

Build setup

inline-resc source.js inlined.js --resc:TEMPLATE template.html

or

// build.js
const InlineResource = require("inline-resource-literal");
const fs = require('fs');

const file = fs.readFileSync('./source.js').toString();

const inlined = (new InlineResource({
    "TEMPLATE": './template.html'
})).inline(file);

fs.writeFileSync('./inlined.js', inlined);

Output

// inlined.js
element.innerHTML = "<p>domain is: " + document.domain + "</p>\n<p>language is: " + navigator.language + "</p>";

API

Check out the .d.ts file.

1.2.2

3 years ago

1.2.0

3 years ago

1.2.1

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago