Reputation: 7772
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?
Upvotes: 1
Views: 1723
Reputation: 2820
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)
Upvotes: 4
Reputation: 4138
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.
Upvotes: 1
Reputation: 2502
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, e.g.
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
Upvotes: 2