Javascript HTML5 Boilerplate plugins.js

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4572659/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 13:02:08  来源:igfitidea点击:

HTML5 Boilerplate plugins.js

javascripthtml5boilerplate

提问by Matrym

How is one expected to include additional js files in plugins.js? Is the expectation that we just copy and paste the contents of each plugin there? Or is there some method of doing a js include that I should be using?

如何在 plugins.js 中包含额外的 js 文件?是否期望我们只是将每个插件的内容复制并粘贴到那里?或者是否有一些方法可以执行我应该使用的 js 包含?

Specifically, I'd like to see an example of goes within this function:

具体来说,我想看看这个函数中的一个例子:

// remap jQuery to $
(function($){

})(this.jQuery);

回答by borkweb

That section of the html5boilerplate is sort of an abbreviation of what should/could go there.

html5boilerplate 的那部分是什么应该/可以去那里的缩写。

You can approach plugins.js a few ways:

您可以通过以下几种方式处理 plugins.js:

  1. Ignore it and include all of your JS plugins as separate files (undesirable)
  2. Manually concatenate and minify the plugin files (this is a pain to maintain)
  3. Use a script to concatenate them (and cache it) at run-time (like this)
  4. Use a makefile to concatenate/compress like a ninja (like this)
  5. Use a slick JS library like yepnope.jsto asynchronously load your plugin files as needed.
  1. 忽略它并将您所有的 JS 插件作为单独的文件包含在内(不可取)
  2. 手动连接和缩小插件文件(维护起来很痛苦)
  3. 使用脚本在运行时连接它们(并缓存它)(像这样
  4. 使用 makefile 像忍者一样连接/压缩(像这样
  5. 使用像yepnope.js这样的 JS 库来根据需要异步加载您的插件文件。

There's a lot of options for including your JS plugins...you'll have to weigh them yourself, of course. I usually use options 3 or 4, though I need to start using 5.

包含您的 JS 插件有很多选择……当然,您必须自己权衡。我通常使用选项 3 或 4,但我需要开始使用 5。

As for what goes in the snippet of code that you gave:

至于您提供的代码片段中的内容:

(function($){
  // This is a wrapper for your jQuery stuff 
})(this.jQuery);

You'll see that block of code wrapping a lot of jQuery plugins (check the docs). It can be used to wrap your jQuery-specific code so you can make use of $while keeping your site in jQuery compatibility mode...which lets your site play nicely with other libraries that may use $as well.

您会看到该代码块包装了许多 jQuery 插件(查看文档)。它可用于包装特定于 jQuery 的代码,以便您$在保持站点处于 jQuery 兼容模式的同时使用它……这使您的站点可以与其他可能使用的库很好地配合使用$