meta-inline

Pull in source files, inlining them where indicated by comment meta-tags.

npm install meta-inline
16 downloads in the last week
32 downloads in the last month

meta-inline

Replace comment meta-data tags with source from the referenced file.

Installation

npm install -g meta-inline

Usage

meta-inline source.js > output.js

The source file with all inline tags replaced, is output to STDOUT.

Tags

Tags are always block comments and always start with the word "inline" followed by a file name. Relative file names are relative to the file that contains the tag.

/* inline foo.js */

Multiple file names can be comma separated...

/* inline foo.js, bar.js */

... or newline separated.

/* inline
    foo.js
    bar.js
*/

The entire tag will be replaced by the source of the files referenced by the tag. If the inlined source also contains tags, those tags will be processed recursively.

Quoted Block Text

You can also inline a block of text by preceding the tag with a pair of double "" or single '' quotes. There must be no space between the comment and the quotes. Useful since JavaScript doesn't support anything like heredoc, and its support for multi-line strings is troublesome.

var str = ""/* inline foo.js */;

Given a file foo.js which contains the following...

"Hello"
World!
\

... then the tag (including the preceding quote pair) will become the following.

var str = "\"Hello\"\nWorld!\n\\";

Notice that appropriate quotes, newline characters, and backslashes have been escaped. if you were to console.log(str), then text identical to what's in foo.js would be output to the console.

npm loves you