Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
jsbundle takes your Node modules and makes them work in the browser.
It finds all require calls in your code and includes the necessary module files. Then, it wraps all these modules using the Node variant of CommonJS module headers.
It handles node_modules directories and package.json files just like Node does.
It comes with a "Dev CDN" that will watch your files for changes and serve the latest jsbundled version of your code via local HTTP.
It has good error handling and runs without any configuration.
[JSBUNDLE_ENV=<env>] jsbundle <entry_file> [config_file]
Bundle up entry_file and all its dependencies, optionally using configuration specified in config_file, and write it to stdout. If no config_file is specified, jsbundle will look for a jsbundle.json file in the current working directory and use that if it exists.
This command is basically equivalent to running:
node <entry_file>
in the sense that when the resulting script is executed in the browser, the module entry_file will be the first module to begin executing.
For production deployment, you'll probably want to pipe the resulting output to the JavaScript minifier of your choice.
[JSBUNDLE_ENV=<env>] devcdn [config_file] [--port tcp_port]
Start a "Dev CDN", serving on tcp_port (default 8081), optionally using configuration specified in config_file. The entry_file passed to jsbundle is determined by the request URL, which will be resolved relative to the current working directory of devcdn. If no config_file is specified, devcdn will look for a jsbundle.json file in the current working directory and use that if it exists.
Test coverage is currently mediocre. You can run tests with:
npm test
All values passed to require in your code must be string literals. Otherwise, jsbundle wouldn't be able to reliably find all the modules to include in the bundled output.
The special variable __filename is equal to the module.id. If you specify the mangleNames option (see below), then the __filename will be the mangled numeric id of the module.
The special variable __dirname doesn't really make sense in the context of browser modules, so while the variable exists, its value is undefined.
{
"default": {
"mangleNames": false,
"beforeBundle": [],
"afterBundle": [],
"extraRequires": {
"_": "underscore",
"Logger": "./ext/logger"
},
"beforeModuleBody": [
"var logger = new Logger(__filename);"
],
"afterModuleBody": [],
"outputFilters": [
"./ext/logger-filter"
]
"loggerFilterLevel": "debug"
},
"production": {
"mangleNames": true,
"loggerFilterLevel": "error",
"bundleUrl": "https://s3.amazonaws.com/xyz/abc.js"
},
"development": {
"outputFilters": []
}
}
jsbundle uses the "default" configuration as a base, and then, depending on the value of the JSBUNDLE_ENV environment variable, overrides or adds more values. In the example above, if the value of JSBUNDLE_ENV is "production", "mangleNames" will be true and the "loggerFilterLevel" will be "error". If the value of JSBUNDLE_ENV is "development", no output filters will be appplied.
By default, jsbundle uses the absolute path of a file as its module id. This is useful for development, but in production it's wasteful and potentially reveals information you want to keep private. If you enable the mangleNames option, module ids will be numeric instead.
An array of arbitrary JavaScript statements to insert before the entire bundle.
An array of arbitrary JavaScript statements to insert after the entire bundle.
You can specify additional requires that jsbundle will automatically add to all of your modules. This is useful for e.g. ensuring you always have underscore available without having to pollute the global namespace or remember to manually require it every time. The value for this configuration option must be an object literal, with keys the variable name for the required module and values the path to the module. Relative paths will be resolved relative to the config file location first, then relative to the jsbundle repository directory.
An array of arbitrary JavaScript statements to insert before every module body.
An array of arbitrary JavaScript statements to insert after every module body.
An array of output filters module files. Relative paths are resolved relative to the config file path first, then relative to the jsbundle repository directory.
Output filters allow you to specify additional ways to transform your module code. They are regular Node modules that must export an init function. This function takes in the jsbundle configuration object as a parameter and returns a second function. The returned function must accept a string containing the source code of a module and return the transformed source code, also as a string.
Example:
exports.init = function(config) {
return function(sourceCode) {
return sourceCode + '; alert("this is a silly output filter");';
};
};
Here is a more useful example.
Note: output filters may require additional configuration options, like the loggerFilterLevel above. These values should be written into the same configuration JSON file. If you write your own output filter, it's probably a good idea to avoid collisions by prefixing additional configuration option names with the name of the output filter.
The bundleUrl will be accessible in your code by accessing module.bundleUrl. If having this information accessible from your code would be useful, set its value to the url from which you'll be serving the bundled code. The "Dev CDN" configures this value automatically for bundles that it serves.
FAQs
Simple, clean, and automatic bundling of your Node modules and packages for use in the browser.
The npm package jsbundle receives a total of 4 weekly downloads. As such, jsbundle popularity was classified as not popular.
We found that jsbundle demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.