Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用JSPM填充jQuery插件?_Jquery_Systemjs_Jspm - Fatal编程技术网

如何使用JSPM填充jQuery插件?

如何使用JSPM填充jQuery插件?,jquery,systemjs,jspm,Jquery,Systemjs,Jspm,将现有项目移动到jspm,我有一些定制的jQuery插件,例如 // path/to/mycustomplugin.js $.fn.myCustomPlugin = function (options) { //something here }; 也就是说,它没有以任何方式向jspm注册。我想我可以添加一个垫片: // config.js shim: { "packages": { "customplugin": { "main": "custom

将现有项目移动到jspm,我有一些定制的jQuery插件,例如

//  path/to/mycustomplugin.js

$.fn.myCustomPlugin = function (options) {
   //something here
};
也就是说,它没有以任何方式向jspm注册。我想我可以添加一个垫片:

// config.js
shim: {
  "packages": {
      "customplugin": {
          "main": "customplugin",
          "format": "global",
          "deps": ["jquery"],
          "exports": "$.myCustomPlugin"
      }
   }
},
map : {
   "customplugin" : "path/to/mycustomplugin"
}
然后在应用程序中导入:

import customplugin from "customplugin"
但它不起作用-该文件从未加载,并且

$(element).myCustomPlugin()

没有定义。关于这方面的文档很难找到。

似乎您的垫片有误。请尝试以下操作:

{
  "jspm": {
    "dependencies": {
      "jquery": "npm:jquery@^2.2.0",
      (...)
    },
    "shim": {
      "custom-jquery": {
        "deps": ["jquery"],
        "exports": "$"
      }
    },
    (...)
  }
}
此外,在自定义插件中,不要忘记导入查询:

import $ from 'jquery';

$.fn.myCustomPlugin = function (options) {
  //something here
};

你有工作代码要显示吗?我还尝试使用JSPM从github导入第三方Jquery插件,它可以很好地加载库,但不调用方法。但是没有控制台错误。