我正在尝试为formBuilder创建一个流星包装程序包。
Package.describe({
summary: "jQuery Form Builder by kevinchappell. Repackaged for Meteor.",
version: "0.1.0",
name: "mycompany:jquery-formbuilder",
git: ""
});
Package.onUse( function( api ) {
api.versionsFrom( 'METEOR@1.2.1' );
api.use( [ 'jquery', 'ecmascript', 'fourseven:scss' ] );
api.addFiles([
// Form Builder Files
"lib/formBuilder/src/sass/base/_animation.scss",
"lib/formBuilder/src/sass/base/_bs.scss",
"lib/formBuilder/src/sass/base/_font.scss",
"lib/formBuilder/src/sass/base/_mixins.scss",
"lib/formBuilder/src/sass/base/_variables.scss",
"lib/formBuilder/src/sass/_controls.scss",
"lib/formBuilder/src/sass/_kc-toggle.scss",
"lib/formBuilder/src/sass/_stage.scss",
"lib/formBuilder/src/sass/form-builder.scss",
"lib/formBuilder/src/js/htmlentities.js",
"lib/formBuilder/src/js/helpers.js",
"lib/formBuilder/src/js/events.js",
"lib/formBuilder/src/js/kc-toggle.js",
"lib/formBuilder/src/js/form-builder.js",
"lib/formBuilder/src/js/to-xml.js",
"lib/formBuilder/src/js/polyfills.js",
// Fonts
"lib/formBuilder/src/fonts/fontello/css/animation.css",
"lib/formBuilder/src/fonts/fontello/css/form-builder-font.css",
// Form Render Files
"lib/formBuilder/src/js/form-render.js",
"lib/formBuilder/src/sass/form-render.scss"
]);
api.addAssets([
"lib/formBuilder/src/fonts/fontello/font/form-builder-font.eot",
"lib/formBuilder/src/fonts/fontello/font/form-builder-font.svg",
"lib/formBuilder/src/fonts/fontello/font/form-builder-font.ttf",
"lib/formBuilder/src/fonts/fontello/font/form-builder-font.woff",
"lib/formBuilder/src/fonts/fontello/font/form-builder-font.woff2"
], 'client');
});
Package.onTest( function( api ) {
api.use(['tinytest', 'test-helpers'], ['client', 'server']);
api.use('jquery', 'client');
api.use('mycompany:jquery-formbuilder');
api.addFiles('mycompany:jquery-formbuilder-tests.js');
});
但我一直收到错误:jQuery is not defined
图书馆尝试在多个地方使用jQuery
。我尝试用jQuery
替换这些$
引用。但我仍然收到错误$ is not defined
我再次尝试添加导出语句
api.export( '$', 'client' )
但问题仍然存在。
包装jquery库的正确方法是什么?
答案 0 :(得分:1)
我发现你的代码存在一个根本性的缺陷。 jQuery库应该用在客户端代码上,因为你没有在api.addFiles(...,[' client',' server'])中指定这个,这个最终将成为编译错误。您的api.addFiles(...)未显式添加要在服务器和客户端上运行的文件,并最终在" jquery模块中未定义"。我还强烈建议单独添加样式文件和js文件,并在api.addFiles()上明确,以避免这种编译错误。我会按如下方式重构您的代码:
Package.onUse( function( api ) {
api.versionsFrom( 'METEOR@1.2.1' );
api.use( [ 'jquery', 'ecmascript', 'fourseven:scss' ] );
api.addFiles([
"lib/formBuilder/src/js/htmlentities.js",
"lib/formBuilder/src/js/helpers.js",
"lib/formBuilder/src/js/events.js",
"lib/formBuilder/src/js/kc-toggle.js",
"lib/formBuilder/src/js/form-builder.js",
"lib/formBuilder/src/js/to-xml.js",
"lib/formBuilder/src/js/polyfills.js"
// Form Render Files
"lib/formBuilder/src/js/form-render.js"
], 'client');
api.addAssets([
// Form Builder Files
"lib/formBuilder/src/sass/base/_animation.scss",
"lib/formBuilder/src/sass/base/_bs.scss",
"lib/formBuilder/src/sass/base/_font.scss",
"lib/formBuilder/src/sass/base/_mixins.scss",
"lib/formBuilder/src/sass/base/_variables.scss",
"lib/formBuilder/src/sass/_controls.scss",
"lib/formBuilder/src/sass/_kc-toggle.scss",
"lib/formBuilder/src/sass/_stage.scss",
"lib/formBuilder/src/sass/form-builder.scss",
// Fonts
"lib/formBuilder/src/fonts/fontello/css/animation.css",
"lib/formBuilder/src/fonts/fontello/css/form-builder-font.css",
"lib/formBuilder/src/sass/form-render.scss"
], 'server');
api.addAssets([
"lib/formBuilder/src/fonts/fontello/font/form-builder-font.eot",
"lib/formBuilder/src/fonts/fontello/font/form-builder-font.svg",
"lib/formBuilder/src/fonts/fontello/font/form-builder-font.ttf",
"lib/formBuilder/src/fonts/fontello/font/form-builder-font.woff",
"lib/formBuilder/src/fonts/fontello/font/form-builder-font.woff2"
], 'client');
永远记住要明确你的api.addFiles(...);