使用requirejs优化和加载外部依赖项 [英] Optimizing and loading external dependencies with requirejs

查看:88
本文介绍了使用requirejs优化和加载外部依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要Facebook SDK的模块.我想知道如何配置SDK的加载,以便RequireJS优化器可以正确处理它.

I have a module that requires the Facebook SDK. I'm wondering how I should configure loading of the SDK so that it's handled properly by the RequireJS optimizer.

在应用中

require.config({
  paths: {
      'facebook' : '//connect.facebook.net/en_US/all'
  }
});

在构建配置文件中:

{
  ...
  paths: {
     'facebook' : 'empty:'
  }
}

据我了解,上面的代码强制优化器跳过该脚本的优化.问题是,优化后不再加载SDK.

As far as I understand it, the code above forces the optimizer to skip optimization of that script. The problem is, the SDK is no longer loaded after optimization.

推荐答案

在构建过程中,我使用Almond作为AMD加载程序,而不是RequireJS.看来Almond(0.2.0)不支持以这种方式加载外部依赖项.在优化过程中,我放弃了Almond并切换回捆绑RequireJS并成功.

As part of the build process I was using Almond as the AMD loader rather than RequireJS. It appears Almond (0.2.0) does not support loading external dependencies this way. I dropped Almond and switched back to bundling RequireJS during optimization and it worked.

http://requirejs.org/docs/optimization.html#onejs

这篇关于使用requirejs优化和加载外部依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆