Node and npm compatibility
Montage fully supports CommonJS Modules and Packages. It also supports some of the extensions from NodeJS and npm:
- module.exports: Modules that do not have cyclic dependencies
(modules with dependencies that in turn ultimately depend their own
exports) can redefine their exports object by assigning to
- dependencies: If a package declares a package dependency using
dependenciesproperty, Montage looks for that package in the package’s
node_modulessubdirectory. Mr also supports the case where a package with the same name is already loaded by a parent package. Unlike NPM, with Montage packages, you can override the location of the
node_modulesdirectory with the
directories.packagesproperty, or use mappings to find individual packages in alternate locations or give them different local names.
- devDependencies: Development dependencies are treated the same as
dependencies, except in production mode where they are ignored.
- JSON: Resources with the
.jsonextension can be loaded as JSON formatted modules.
There are some differences with the Node.js module system you should be aware of:
dependenciesversion predicates are ignored.
__dirnameare not injected into module scope. Consider using
- Because Mr cannot know if a URL points to a file or a directory, when you
require a directory
index.jsis not sought. To make a package using an
index.jscompatible with Montage Require, add a
package.json. See the package API