bundle
steal-tools.bundle
Similar to build it creates a bundle of modules and its dependencies but a glob pattern can be provided to filter out module during the build.
stealTools.bundle(config, options)
Parameters
-
config
{StealConfig}
Specifies configuration values to set on Steal's loader.
-
options
{BuildOptions}
OptionalSpecifies the behavior of the build.
Returns
{Promise<BuildResult>}
A Promise that resolves when the build is complete.
Use
The following uses steal-tools
bundle
method to programatically build out the "my-app" dependencies in thenode_modules
folder.This will build bundles at the root of your project like:
To load the bundles, a html page should have a script tag like:
filter
The
filter
option specifies a glob pattern what modules are included in the bundle.It can be a string with a single pattern or an array if multiple patterns are needed; the multimatch library is used to support multiple patterns, check its docs to see how the matching works.
The
filter
value used in the example above will create a bundle of the modules loaded by the application which are located in thenode_modules
folder.dest
The
dest
option specifies a folder where the bundles are written out.This will build bundles like:
To load the bundles, a html page should have a script tag like:
Dependencies bundle and development bundles
The main use case for custom bundles is to speed up the loading time of your application during development; you can achieve this by bundling up your application dependencies (which hopefully change a lot less than the actual application code) and only load one file instead of each individually.
We call a dependencies bundle a bundle that only includes the application dependencies (all the modules in the
node_modules
folder if you are usingnpm
), to generate it you would do something like:In order to load a dependencies bundle you would need to add the
deps-bundle
attribute to the StealJS script tag, like this:We call a development bundle a dependencies bundle that also includes the StealJS configMain module; in order to generate it you'd do something like:
Unlike a dependencies bundle, a development bundle has to be loaded before StealJS configMain is loaded. In order to do that, StealJS provides a
dev-bundle
propert that you can set to the script tag so it loads the bundle correctly, like this:You will get faster load times with development bundles, with the downside that you will need to generate the bundle each time your config module changes or your application might no load at all.