-
Notifications
You must be signed in to change notification settings - Fork 3
No more imports directory #135
Comments
I hope this one doesn't happen. We have a legacy project that still has a lot of code that relies on globals. All new code uses imports, but the fact that we can have both right now and old code doesn't break is amazing and it would be a big loss if we couldn't update to future versions of Meteor due to this change happening. I don't fully understand the benefit of this change either. If you don't want globals don't use them. The current system allows for both which should make everyone happy. |
I think this should be done, but not be the default. It could be a flag in |
no |
But it would be also important then to have a directory for client and server with "always import" semantics. |
Sometimes eager loading is useful, I find myself often creating a new meteor project, going directly to /server, and creating some methods, some api endpoints, and it just works nicely. But for a serious project I only have 2 proxy files in client/main.js and server/main.js that do nothing but import from /imports. It feels a bit stupid. I feel like Meteor is the perfect hybrid between fast prototyping and a serious enterprise app. We all started with it because of its simplicity, let's not take this away. Besides this, I also think that eager-loading for client-side will be something useful later in the future, especially if a pattern will emerge that defines routing at component level (Just a hunch)
If we want a complex solution we can go with something like: package.json or meteor settings, or a special .meteor/config.js file (I can't say which is best)) "meteor-load": {
"eager": {
"client": ["./client"],
"server": ["./server"],
"both": ["./lib"]
},
"entry": {
"client": "./imports/startup/client/index.js",
"server": "./imports/startup/server/index.js"
}
} But if we do this, what impact would it have on reloading ? Would we still benefit from a server-only restart if I modify something from server ? Another elegant way I foresee is:
|
I think only importing files which are specified would be a huge improvement. It would also allow for building inside of the project directory and preventing this error:
|
Given the valid concerns that have been raised in this thread (thanks!), I just want to (re)assure you all that this feature will be implemented in a way that adds flexibility in terms of which directories/modules are eagerly loaded, rather than just eliminating the |
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 above would cause that platform 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 informed 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. For example, #8165 has been blocked for a long time because we haven't had a standard way to specify a custom command to install npm packages. Once we have a precedent for using the "meteor" section of `package.json`, it will be much easier to consider additional options, even though we should maintain a rigorous standard of necessity.
This is happening! |
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.
@benjamn that's a very noble ulterior motive :) Personally. I'd be looking forward to simplifying the configuration of my meteor+webpack build after this upgrade. How would it affect the "absolute" import paths though? i.e. would the equivalent of |
It’s relative to the root directory of the application, so I think you would want If we made absolute imports (with an initial Does that answer your question? |
@benjamn, my question was actually entirely focused on the first paragraph of your answer. You're right that I want Just to give you some more context of my setup: the As a side note, I've always found the absolute imports (with initial |
If that setup works with Meteor now, I’m pretty sure we can keep it working with this feature, though I would encourage you to try the latest beta |
I tested a minimal app created with: meteor create --release 1.6.2-beta.12 --minimal test-meteor-1.6.2 Works: Can't test my whole app for now, but hope to do so some time next week. If it's open for consideration, I'd suggest supporting the base path imports so that:
|
@gaurav- You need to do |
Which release is the |
@merlinpatt Meteor 1.7 (and 1.7.0.1) has it! Given that new Meteor apps no longer need an |
follow up question here :) |
What great work. Thank you, thank you, thank you! Finally refactored the |
Migrated from: meteor/meteor#8341
The text was updated successfully, but these errors were encountered: