如何在我的 meteor1.3 typescript 项目中全局提供 tether/anything-else?

how to provide tether/anything-else globally in my meteor1.3 typescript project?

我几乎没有尝试在 meteor1.3 设置中获取我现有的 ng2 原型 运行。到目前为止,我正在使用 webpack 构建原型,并且有一个提供的插件可以在模块构建期间提供 jQuery 或 Tether 之类的东西:

plugins: [
  new ProvidePlugin({
     $: "jquery",
     jQuery: "jquery",
     "window.jQuery": "jquery",
     "window.Tether": "tether"
  })
]

如您所见,我对 "tether" 做了同样的事情,因为它仍然是 bootstrap 4 alpha 所需的库。

现在我想知道如何在我的 meteor1.3 项目中实现相同的目标..?正如包 "angular2-meteor" 的变更日志中所写,它现在正在使用 webpack 来构建所有内容。

angular2-meteor changelog

所以,应该可以在meteor1.3中再次使用同一个provide plugin吧?但是……怎么办?

来自 "angular2-meteor" 的 github 问题线程:

there are multiple ways: you could install https://atmospherejs.com/coursierprive/tether, or, since Meteor 1.3 prefers NPM now, you could install Tether NPM and require it before you use bootstrap 4, or, if you want more control and modularity, you could create own local package (in the packages folder) with all dependencies (added from NPMs) you need including Tether (similar to the way angular2-runtime done in this repo).

我会试试这个,我已经确定这会成功:)非常感谢@barbatus ;)

更新:

好的,我要使用 npm 包解决方案,我已经安装了 tether。如果没有,请先执行此操作:

npm install --save tether

现在,单个 require 语句是不够的.. bootstrap 4 我试图完全包含的是要求 window.Tether 函数。所以我最终这样做了:

let Tether = require('tether');
window.Tether = Tether;

// import all bootstrap javascript plugins
require('bootstrap');

很酷,现在还有一个 typings 定义文件,只需按 运行:

添加即可
typings install --save --ambient tether

将其添加到 window 全局上下文后,错误消失了...但是好吧,通过 webpack 提供的插件的解决方案感觉仍然更清晰 -> 它将分别为每个模块提供 Tether 对象在构建期间,所以它最终不会生活在 window 全局上下文中。但我现在很幸运 运行 :)

PS:jQuery 无论如何都是由 meteor 提供的,这就是它已经足够 运行 仅包括 tether 的原因。

更新:是的 jQuery 默认包含 - 但它只是您 /.meteor/packages 文件中的一个包 ;)