NPM module for concatenating files and generating source maps.
The original concat-with-sourcemaps
module uses system memory (RAM) to store the concatencated files. While it makes concatenation fast,
this can be a problem for machines with less RAM. This module addresses this problem by (optionally) storing the concatenated contents into a temporary
file while allowing the Node.js's garbage collector to free some memory used in storing the file contents.
npm i async-concat-with-sourcemaps
async function usingAsyncConcat() {
// store concatenated file in /tmp directory
var concat = new Concat(true, 'all.js', '\n', '/tmp');
await concat.add(null, "// (c) John Doe");
await concat.add('file1.js', file1Content);
await concat.add('file2.js', file2Content, file2SourceMap);
var concatenatedContent = await concat.content();
var sourceMapForContent = await concat.sourceMap();
}
Initialize a new concat object.
Parameters:
- generateSourceMap: whether or not to generate a source map (default: false)
- outFileName: the file name/path of the output file (for the source map)
- separator: the string that should separate files (default: no separator)
- tmpDir: (optional) directory used to store concatencated files. Passing
undefined
will use system memory.
Add a file to the output file. Returns a Promise<void>
.
Parameters:
- fileName: file name of the input file (can be null for content without a file reference, e.g. a license comment)
- content: content (Buffer or string) of the input file
- sourceMap: optional source map of the input file (string). Will be merged into the output source map.
The resulting concatenated file content (Buffer). Returns a Promise<Buffer>
.
The resulting source map of the concatenated files (string). Returns a Promise<string | undefined>
.
Path to the temporary file.