npm
{*}
moduleName!npm
Parameters
-
moduleName
{moduleName}
The moduleName of the file you want to process. This will normally be a package.json of your base application.
{*}
{moduleName}
The moduleName of the file you want to process. This will normally be a package.json of your base application.
Use
The
npm
plugin makes it easy to work with npm packages. By pointing it at apackage.json
, you will be able to import npm packages as modules.By default, if stealPath points to steal.js within node_modules like:
configMain will point to
"package.json!npm"
. Thenpm
plugin readspackage.json
and sets a normalize and locate hook.Note: if you are using npm 3 see the npmAlgorithm option below.
npm Module names
Package dependency module names are converted to look like:
For example, code that import's jQuery like:
might actually import:
Configuration
package.json
configures the behavior of a package and even dependency packages. This section lists the configurable properties and behaviors that steal uses.package.main
Specifies the main property unless it is overwritten by
package.browser
orpackage.steal.main
.package.browser
Specifies browser-specific overwrites for module file resolution. This behaves like Browserify's browser field.
package.globalBrowser
Global browser specific overwrites for module file resolution. These mapping take effect for all projects. Use sparingly.
package.steal
By default, any property on the package.steal object is passed to config. However, the following properties have special behavior:
package.steal.main
The moduleName of the initial module that should be loaded when the package is imported. For example:
When
my-module
is imported,my-module@1.2.3#my-main
will be the actual module name being imported. This path thatmy-main
will be found depends on thedirectories.lib
setting.package.steal.map
The map config works similar to the base map behavior. However, both the keys and values are converted to npm module names. The keys and values must:
./
to map modules within the package like"./src/util"
, orpackageName#./modulePath
to map direct dependencies of the package.package.steal.meta
The meta config works similar to the base meta behavior. However, the module names must:
./
to add metadata to modules within the package like"./src/util"
, orpackageName#./modulePath
to add metadata to direct dependencies of the package.Example:
package.steal.npmIgnore
Use npmIgnore to prevent package information from being loaded for specified dependencies in the
peerDependencies
,devDependencies
ordependencies
. The following ignores a package.json'sdevDependencies
andcssify
. But all other dependencies will be loaded:The following packages are ignored by default:
package.steal.npmDependencies
Like
npmIgnore
but affirmative. If used alone will only include the dependencies listed. If used in conjunction withnpmIgnore
acts as an override. For example the following config:Will load
one
but ignoretwo
.When used in conjuction with
npmIgnore
:Even though
npmIgnore
is set to ignore alldevDependencies
the use ofnpmDependencies
acts as an override. The packageone
will be loaded, but nottwo
orthree
.package.steal.npmAlgorithm
Used to determine which algorithm is used to look up packages.
The default algorithm is
flat
. We assume that you are using npm 3 or higher. See here more about the flat file structure of npm 3.If you are using npm 2 or pnpm, your dependencies of
node_modules
will be nested. StealJS can handle the lookup by settingnpmAlgorithm
tonested
.package.steal.ignoreBrowser
Set to true to ignore browserfy's
browser
andbrowserify
configurations.package.steal.directories
Set a folder to look for module's within your project. Only the
lib
directory can be specified.In the following setup,
my-project/my-utils
will be looked for inmy-project/src/my-utils.js
:package.steal.configDependencies
Defines dependencies of your npm package. This is useful for loading modules, like extensions, that need to be initialized before the rest of your application is imported, e.g:
package.steal.plugins
Specifies packages that are used as plugins. These packages will be prefetched so that they're configuration will be applied before your app loads. An example is steal-css.