package
convert module usage to inline expressions
npm install static-moduleGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
convert module usage to inline expressions
Here's a simplified version of the brfs module using static-module.
brfs converts fs.readFileSync(file) calls to inline strings with the contents
of file included in-place.
var staticModule = require('static-module');
var quote = require('quote-stream');
var fs = require('fs');
var sm = staticModule({
fs: {
readFileSync: function (file) {
return fs.createReadStream(file).pipe(quote());
}
}
}, { vars: { __dirname: __dirname + '/brfs' } });
process.stdin.pipe(sm).pipe(process.stdout);input:
$ cat brfs/source.js
var fs = require('fs');
var src = fs.readFileSync(__dirname + '/x.txt');
console.log(src);output:
$ node brfs.js < brfs/source.js
var src = "beep boop\n";
console.log(src);var staticModule = require('static-module')Return a transform stream sm that transforms javascript source input to
javascript source output with each property in the modules object expanded in
inline form.
Properties in the modules object can be ordinary values that will be included
directly or functions that will be executed with the statically
evaluated arguments from the source
under an optional set of opts.vars variables.
Property functions can return streams, in which case their contents will be piped directly into the source output.
Otherwise, the return values of functions will be inlined into the source in place as strings.
Use opts.varModules to map whitelisted module names to definitions that can be
declared in client code with var and will appear in static expressions like
opts.vars.
For example, to make this code with path.join() work:
var fs = require('fs');
var path = require('path');
var src = fs.readFileSync(path.join(__dirname, 'x.txt'), 'utf8');
console.log(src);you can do:
var staticModule = require('static-module');
var quote = require('quote-stream');
var fs = require('fs');
var sm = staticModule({
fs: {
readFileSync: function (file) {
return fs.createReadStream(file).pipe(quote());
}
},
varMods: { path: require('path') }
}, { vars: { __dirname: __dirname + '/brfs' } });
process.stdin.pipe(sm).pipe(process.stdout);Use opts.parserOpts to set additional options for the
acorn parser.
Set opts.sourceMap to true to generate a source map and add it as an inline
comment. You can add opts.inputFilename to configure the original file name
that will be listed in the source map.
With npm do:
npm install static-moduleMIT
gkatsev
me@gkatsev.com
maxogden
max@maxogden.com
thlorenz
thlorenz10@gmail.com
terinjokes
terinjokes@gmail.com
jmm
npm-public@jessemccarthy.net
mellowmelon
palmermebane@gmail.com
ashaffer88
darawk@gmail.com
balupton
b@lupton.cc
cwmma
calvin.metcalf@gmail.com
jprichardson
jprichardson@gmail.com
indutny
blackhole@livebox.sh
jryans
jryans@gmail.com
sethvincent
sethvincent@gmail.com
yoshuawuyts
javascript@yosh.is
ungoldman
ungoldman@gmail.com
ahdinosaur
michael.williams@enspiral.com
elnounch
contact@elnounch.net
parshap
parshap+npm@gmail.com
yerkopalma
yerko.palma@usach.cl
forbeslindesay
forbes@lindesay.co.uk
leichtgewicht
martin.heidegger@gmail.com
garann
garann@gmail.com
bret
bcomnes@gmail.com
anandthakker
vestibule@anandthakker.net
mattdesl
dave.des@gmail.com
hughsk
hughskennedy@gmail.com
fpereira1
pereira.filype@gmail.com
goto-bus-stop
renee@kooi.me
bpostlethwaite
post.ben.here@gmail.com
emilbayes
github@tixz.dk
stevemao
maochenyan@gmail.com
pkrumins
peteris.krumins@gmail.com
tehshrike
me@JoshDuff.com
defunctzombie
shtylman@gmail.com
lukechilds
lukechilds123@gmail.com
raynos
raynos2@gmail.com
Estimated unpacked size across 48 packages.
3.5 MB
Includes dependencies.
14 direct · 8 outdated
^1.0.1
1.0.4
~2.0.3
5.0.12
~0.1.4
0.1.4
^1.11.1
2.1.0
^1.3.0
2.0.1
~1.6.0
2.0.0
^1.6.0
1.13.4
^2.0.1
2.1.2
~2.3.3
4.8.0
1.0.4
1.1.0
^1.5.1
2.0.0