static-module

WebJar for static-module

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

static-module
Last Version

Last Version

3.0.4
Release Date

Release Date

Type

Type

jar
Description

Description

static-module
WebJar for static-module
Project URL

Project URL

https://www.webjars.org
Source Code Management

Source Code Management

https://github.com/browserify/static-module

Download static-module

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/static-module/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>static-module</artifactId>
    <version>3.0.4</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/static-module/
implementation 'org.webjars.npm:static-module:3.0.4'
// https://jarcasting.com/artifacts/org.webjars.npm/static-module/
implementation ("org.webjars.npm:static-module:3.0.4")
'org.webjars.npm:static-module:jar:3.0.4'
<dependency org="org.webjars.npm" name="static-module" rev="3.0.4">
  <artifact name="static-module" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='static-module', version='3.0.4')
)
libraryDependencies += "org.webjars.npm" % "static-module" % "3.0.4"
[org.webjars.npm/static-module "3.0.4"]

Dependencies

compile (14)

Group / Artifact Type Version
org.webjars.npm : readable-stream jar [2.3.3,2.4)
org.webjars.npm : scope-analyzer jar [2.0.1,3)
org.webjars.npm : acorn-node jar [1.3.0,2)
org.webjars.npm : magic-string jar [0.25.1]
org.webjars.npm : static-eval jar [2.0.5,3)
org.webjars.npm : convert-source-map jar [1.5.1,2)
org.webjars.npm : through2 jar [2.0.3,2.1)
org.webjars.npm : object-inspect jar [1.6.0,2)
org.webjars.npm : merge-source-map jar [1.0.4]
org.webjars.npm : escodegen jar [1.11.1,2)
org.webjars.npm : duplexer2 jar [0.1.4,0.2)
org.webjars.npm : shallow-copy jar [0.0.1,0.1)
org.webjars.npm : has jar [1.0.1,2)
org.webjars.npm : concat-stream jar [1.6.0,1.7)

Project Modules

There are no modules declared in this project.

static-module

convert module usage to inline expressions

example

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);

methods

var staticModule = require('static-module')

var sm = staticModule(modules, opts={})

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.

install

With npm do:

npm install static-module

license

MIT

org.webjars.npm

Versions

Version
3.0.4
3.0.3
2.2.5
2.2.2
2.2.0
1.5.0
1.1.0