google closure compiler and jquery

后端 未结 1 2026
长情又很酷
长情又很酷 2021-02-05 21:13

I copy-pasted my js code into the google compiler and when I copied it back into my application it didn\'t work. I realized that my code needs jquery so I copied the jquery code

相关标签:
1条回答
  • 2021-02-05 21:59

    Use @externs_url to "import" symbols in Google's Closure compiler:

    // @externs_url https://raw.githubusercontent.com/google/closure-compiler/master/contrib/externs/jquery-1.9.js
    

    I recommend to use one of the externs as defined in contrib/externs, which only includes the names of all methods.

    Example

    // ==ClosureCompiler==
    // @compilation_level ADVANCED_OPTIMIZATIONS
    // @externs_url https://raw.githubusercontent.com/google/closure-compiler/master/contrib/externs/jquery-1.9.js
    // ==/ClosureCompiler==
    $(document).ready(function(){alert(0);});  // Input
    

    Output:

    $(document).ready(function(){alert(0)});
    
    0 讨论(0)
提交回复
热议问题