代码之家  ›  专栏  ›  技术社区  ›  Dan YOU

如何将jQuery插件导入babel应用程序

  •  0
  • Dan YOU  · 技术社区  · 7 年前

    在这个应用程序中,我需要使用 jQuery plugin 对于一些DOM操作。我不想全局公开jQuery,然后使用脚本标记将插件代码加载到文档中。相反,我希望插件只能在模块中使用:

    import $ from 'jquery';
    // some magic importing pluginName
    
    $('#element').pluginName();   // how to make this work? 
    

    $ 实例化时要显示的变量。

    1 回复  |  直到 7 年前
        1
  •  1
  •   Bhojendra Rauniyar    7 年前

    您需要插件:

    import $ from 'jquery';
    require('path-to-plugin');
    
    $('#element').pluginName();