steal-clone
steal.steal-clone
{function()}
Steal-clone is a module that allows you to clone Steal's loader and provide module definitions that will be used when doing dynamic imports.
clone(moduleOverrides)
Parameters
-
moduleOverrides
{Object}
Module identifiers and definitions used to override modules of the same name. These definitions will be used when importing parent modules using the
import
statement of the returned loader.
Returns
{Object}
The cloned loader.
Use
If you have
moduleA
defined as:and
moduleB
defined as:You can use
clone
to override the definition of moduleB that will be used from within moduleA:Module Identifiers
The keys passed in the
moduleOverrides
object ("moduleB" in the example above) can be any valid module identifier. All of the module syntaxes supported by Steal are supported by steal-clone. If you're using ES6 modules, you can use the same value used in your import statement. Similarly, if you're using CommonJS, you can use the same value that you pass to 'require'.You can also use relative paths to override modules based on where you are using steal-clone:
Module Definitions
The values passed in the
moduleOverrides
object define the exports for that module. In the above example,moduleB
has a single default export.If
moduleB
is defined like:You can override both of the module's exports like this:
Dynamically imported modules
It's possible to provide overrides to modules that will be later dynamically imported. If you have a
moduleC
defined as:You will be able to override the value of
moduleB
. Note that for this to work you must import @loader to use for dynamic loading instead of usingsteal.import
. This is because@loader
will refer to the cloned loader you created where assteal.loader
always refers back to the global loader. Using @loader is always recommended anyways.Use with npm
Steal-clone can be used to override dependencies from npm in the same way as any other module.