transformImport
Loads a module, and its dependencies, and provides a transform method, so they can be written out in another form.
stealTools.transformImport(config, transformOptions)
Loads a module, and all of its dependencies, and returns a function that
can write out all, or parts, of the module and its dependency graph,
so that they don't depend on steal.js
.
Parameters
-
config
{StealConfig}
Specifies configuration values to set on a Steal loader. The main option must be specified. Typically, configPath is also specified, as that is used to set baseURL. Any Steal configuration can be specified; however, most other build configuration values are specified by buildConfig in the config file.
-
transformOptions
{Object}
Configures the behavior of loading the modules, and acts as default values for the resulting transform function's options argument.
Returns
{Promise<transform(moduleName, options)>}
A deferred, which resolves to a function that can write out all or part of the loaded dependency tree.
Use
stealTools.transformImport
lets you transform modules to a different format or form. It's passed a StealConfig, which is used to load modules. Once all modules have been loaded, it provides a transform method that can write out modules:transformImport
andtransform
are low-level functionality. For the majority of projects, export will be a better fit for the most common transformation behavior.Like build, transformImport can be used from the command-line, from Grunt, or programmatically in Node.js. For this example, we're going to use transformImport programmatically, in order to showcase its more advanced functionality:
As you can see, transformImport takes an object containing the configuration and returns a Promise. The promise will return another function (named "transform" in this example) that can be used to generate a string containing a module and its dependencies. By default, the transform function will return the main module; but it can be used to generate any dependency in the graph.