Shim a jQuery plugin with browserify

前端 未结 3 1060
不思量自难忘°
不思量自难忘° 2020-12-30 09:12

Hi I\'m using the grunt browserify task to setup my code, I have shimmed in jQuery and I\'m now trying to include jquery.tablesorter.

Can jquery plugins be used with

3条回答
  •  甜味超标
    2020-12-30 09:32

    Maybe you dont need to use "browserify-shim" section in package.json if you use this extention.

    You can do like here Using Browserify with jQuery Plugins

    I've tried it and it works.

    Example

    package.json

    "browserify": {
        "transform": ["browserify-shim"]
    },
    "browser": {
         "jQuery.translit": "./public_html/js/vendor/jquery/jquery.translit.js"
    },
    "browserify-shim": {
        "jQuery": "global:jQuery"
    }
    

    JS file:

    var $ = require("jQuery"),
        translit = require("jQuery.translit"),  //don't use this variable      
        heading = require("./helper/heading.js");
    $.transliterate("parameter"); //use as regular jQuery plugin instead
    

提交回复
热议问题