如何使用JSPM填充jQuery插件?
将现有项目移动到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
// 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插件,它可以很好地加载库,但不调用方法。但是没有控制台错误。