Require jQuery in Meteor server side

自作多情 提交于 2019-12-19 04:19:08

问题


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

  1. Run $: meteor add meteorhacks:npm
  2. in packages.json specify npm package and it's version { "jquery": 2.1.1 }
  3. Require jQuery Meteor.npmRequire("jquery");
  4. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!