问题
I saw:
https://groups.google.com/forum/#!topic/meteor-core/ZlPPrH7SqrE
http://guaka.org/guaka-jquery-meteor-server-side-try-var-meteor-bootstrap-requirejquery-javascript-0
Server-side jquery
How can one parse HTML server-side with Meteor?
And I have not figured out a way to include jQuery in Meteor server side. Anyone knows?
I tried:
Npm.require('jquery')
Npm.require('jQuery')
But package is not found:
# Npm.require('jquery')
►[Error][Error: Cannot find module 'jquery']
回答1:
Try using this package https://github.com/meteorhacks/npm
- Run
$: meteor add meteorhacks:npm - in
packages.jsonspecify npm package and it's version{ "jquery": 2.1.1 } - Require jQuery
Meteor.npmRequire("jquery"); - fire up your server
$: meteor
回答2:
For Meteor 1.0
Create .meteor/package.json with:
{
"dependencies":{
"jquery": "*"
}
}
Then cd .meteor and run npm install to install jquery in .meteor/node_modules.
Then you can use in server Npm.require('jquery').
And add node_modules in .meteor/.gitignore so you don't push dependencies that will be installed with npm install.
There is a problem though, npm does not keep track versions of installed packages. To do that, run npm shrinkwrap in .meteor, that way, when another developer run npm install in another machine will get the same version you installed.
来源:https://stackoverflow.com/questions/26708437/require-jquery-in-meteor-server-side