简体   繁体   中英

How to structure a large meteor.js application?

So right now I my project is structured so that my server side code lives in a server folder.

I have broken up my javascript into multiple files and was previously using require.js. Right now, I've tried using

Npm.require

and

__meteor_bootstrap__.require

to get the 'exports'object of the different files, but that is not working.

In other words, how do I properly use require.js with Meteor? Or is there some better way of breaking up large javascript files in Meteor?

I suggest you look at building your app entirely out of smart packages. Since 0.6.0, you can have local packages under packages/

As best practice, any app-specific package folders would be namespace-prefixed (example: myapp-billing)

If your goal is to break some of your project into modules that can be released on separate release cycles and perhaps shared with other projects, then you are on the right track by making them into require.js style modules (if you just want to break one big .js into multiple, then do as user728291 suggests).

If you do create multiple require.js style modules, you should completely break those modules out of your Meteor project and put them into separate directories, eg

workspace/ /my-meteor-project/ ...project contents... /reusable-module-1/ package.json reusable-module-1.js /reusable-module-2 package.json reusable-module-2.js

Then, install these Npm modules locally using npm link , or share them with the world by using npm publish . Then, here is a discussion of best practices for including Npm modules in Meteor applications

I think you are trying to make a package. Here is an example of Npm.require() being used in a package.

Also packages already exist for many common js libraries so check atmosphere and maybe you will not need to write your own package.

You can also just place .js files in a directory structure like this without needing to use Npm.require and packages which may be easiest if you already have code working in one .js file on the server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM