forked from meteor/meteor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support a meteor.mainModule section in application package.json files.
meteor/meteor-feature-requests#135 This change allows applications to specify specific entry points for each architecture, without relying on `imports` directories to determine the eagerness/laziness of modules. In other words, it will finally be possible to build a Meteor app without a special `imports` directory. Specifically, if `packageJson.meteor.mainModule[architecture]` is defined, all modules for that architecture will be lazy except for the specified module, which will be loaded eagerly. Possible values for `architecture` include "client", "server", "web", "web.browser", "web.cordova", "os", and so on, just like the second argument to `api.mainModule(file, where)` in Meteor packages. In order to match existing behavior, a Meteor application might include the following in its `package.json` file: "meteor": { "mainModule": { "client": "client/main.js", "server": "server/main.js" } } These architectures are handled independently, so omitting the "client" or "server" property would cause that architecture to revert to standard Meteor loading semantics. In other words, Meteor developers must opt into this functionality, which is crucial for backwards compatibility. Note that this functionality applies only to application modules, since modules in Meteor packages are already lazy by default, and Meteor packages can already specify entry points by calling `api.mainModule` in their `package.js` files. Also note that the loading behavior of non-JavaScript resources is *not* affected by `packageJson.meteor.mainModule`. Only resources added by compiler plugins via `addJavaScript` are subject to the new configuration option. If a compiler plugin calls `addStylesheet` or `addHtml`, those resources will still be included unconditionally in the HTML document rendered by the web server. While you could try to import these resources from JavaScript, you would only be importing any JavaScript resources the compiler plugin registered using `addJavaScript`, and not the actual HTML or CSS resources. I welcome feedback on this decision, but if there's no meaningful way to import a resource, making it lazy just means it won't be loaded at all. An ulterior motive for this feature is to enable Meteor apps to have directory layouts that developers who are not familiar with Meteor can immediately understand. The special meaning of the `imports` directory and the surprising eagerness of modules outside of `imports` have always required some explanation, so this change should reduce that surprise. Because Meteor strives to be a zero-configuration tool, this is currently the only supported option in the "meteor" section of `package.json`, though the available options may be expanded in the future if that's the best/only way to solve important problems. This would involve adding additional methods to the `MeteorConfig` class in `project-context.js`, and then using those methods elsewhere in the `meteor/tools` codebase.
- Loading branch information
Ben Newman
committed
Feb 23, 2018
1 parent
bbd6149
commit ae3ad3b
Showing
4 changed files
with
174 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters