A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/benbria/browserify-transform-tools/wiki/Transform-Configuration below:

Transform Configuration · benbria/browserify-transform-tools Wiki · GitHub

All make*Transform() functions will automatically load configuration for your transform and make it available via transformOptions.config (and through the more detailed transformOptions.configData.)

Configuration is taken first from data passed via options from browserify (either from b.transform(tr, opts) or from the command line. Configuration is then loaded from package.json. If configuration is found in both package.json and in data passed programatically, then keys from the programatic configuartion are copied over top of the configuration from package.json.

All transforms created by make*Transform() receive configuration via transformOptions.configData. The configData object has the following properties:

All modules that rely on browserify-transform-tools can contain a configuration item called 'appliesTo'. This will configure what files the transform will be applied to. For example, users of the "soupify" transform might add the following to their package.json:

"soupify": {
    "appliesTo": {"includeExtensions": [".js"]}
}

This will make soupify apply to all '.js' files, and only to '.js' files, regardless of what was specified in the transform's options.

appliesTo should include exactly one of the following:

The appliesTo key will be stripped from the configuration before being passed to your transform (although it is available in the configData if you need it for some reason.) Note that appliesTo will override the includeExtensions and excludeExtensions provided to any of the make*Transform() functions.

Loading configuration programatically

As of v1.3.1, browserify-transform-tools will load arguments passed via browserify's API or on the command line using the subarg syntax. This is the best way for users to pass configuration to your transform.

Loading Configuration from package.json

The default behavior when looking for package.json is to start from the current working directory, walk up the directory tree until package.json is found, then load the configuration from that file.

If options.fromSourceFileDir is set, then instead the behavior is to start at the source file, walk up the directory tree until package.json is found, and try to load configration from that file. If configuration is not found, then we will continue to walk up the tree until we find another package.json and will try again, recursively. This is similar to how browserify-shim looks for configuration, and was the default in browserify-transform-tools v1.x. See this issue for further details.

Once package.json is found, configuration is loaded by finding a key in the package.json with the same name as your transform. For example, for a "unbluify" transform, you might set up your package.json to look like:

{
    "name": "myProject",
    "version": "1.0.0",
    ...
    "unbluify": {"newColor": "red"}
}

Or alternatively you can set the "unbluify" key to be a js or JSON file:

{
    "unbluify": "unbluifyConfig.js"
}

And then configuration will be loaded from that file:

module.exports = {
    newColor: "red"
};

Note using a .js file means you can use environment variables to make changes to your configuration. You can also use .coffee files if you are using the Browserify API, and require('coffee-script'); before you do your bundle.

Loading Configuration Manually

If you are writing your own transform which doesn't use a make*Transform() function, you can still use browserify-transform-tools to load configuration from package.json:

var transformTools = require('browserify-transform-tools');

transformTools.loadTransformConfig('myTransform', file, function(err, configData) {
    var config = configData.config;
    var configDir = configData.configDir;
    ...
});

Or synchronously via:

var configData = transformTools.loadTransformConfigSync(...);

There is also a skipFile() function available for deciding whether or not you should process a file, based on the current configuration:

    var configData = transformTools.loadTransformConfigSync(...);
    var shouldSkipFile = transformTools.skipFile(filename, configData);
Legacy programatic configuration

If your users are using the browserify API to bundle their apps, then they can specify the configuration by calling into the configure(config, options) on your transform. This function is created automatically on any transform returned by the make*Transform() functions.

configure() will override any configuration set in package.json. configure() returns a new transform instance and does not modify the existing transform:

myTransform = require('myTransform').configure(
    {colorFile: './colors.json'},
    {configFile: __filename});

If want to modify the configuration on an existing instance, you can call setConfig() with the same options. For example:

myTransform = require('myTransform');
myTransform.setConfig(
    {colorFile: './colors.json'},
    {configFile: __filename});

Both functions take the following options:


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4