在 node_modules 中编译一个包在浏览器中使用 [英] Compile a package in node_modules for use in browser

查看:70
本文介绍了在 node_modules 中编译一个包在浏览器中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚注意到,由于meteor 不会在node_modules 中编译包,因此我们的网站无法在iOS 10 上加载.据报道,iOS 10 目前在超过16% 的iOS 设备上使用到这个来源:https://data.apteligent.com/ios/(这是相当高的)

I just noticed that, because meteor doesn't compile packages in node_modules, our website doesn't load on iOS 10. iOS 10 is currently used on more than 16% of iOS devices, according to this source: https://data.apteligent.com/ios/ (this is quite high)

我做了一些研究,发现你可以选择编译哪些 node_modules 包,但它只会在下一个流星版本中出现:https://github.com/meteor/meteor/pull/9771https://github.com/meteor/meteor/blob/devel/History.md

I did some research and found out that you can choose which node_modules packages to compile, but it's only coming in the next meteor release: https://github.com/meteor/meteor/pull/9771 https://github.com/meteor/meteor/blob/devel/History.md

有什么办法可以更快地拥有此功能?

Any way to have this functionality sooner?

我应该git clone"这个包并手动编译它(如何?),然后包含编译版本并删除 npm 安装的包?

Should I just "git clone" the package and compile it manually (how?) and then include the compile version and remove the npm-installed package?

推荐答案

一种解决方案是将 npm 包作为 git 子模块(或子树)添加到 imports 文件夹中,然后从在那里,就好像这是您自己的代码.这将触发 Meteor 的构建工具.

One solution would be to add the npm package as a git submodule (or subtree) inside your imports folder and then import it from there, as though it was your own code. This will trigger Meteor's build tool.

通过将其保留为 git 子模块,您可以随时通过检查该文件夹中的新版本来更新它,并将其代码与您自己的存储库分开.

By keeping it as a git submodule you can always update it by checking out a new version inside that folder, and keep it's code separate from your own repo.

请注意,拥有子模块会增加使用 git 和处理项目的复杂性.

Note that having submodules increases the complexity of using git and working with your project in general.

在你这样做之前,我会尝试将 node_modules 中的包符号链接到某个地方的导入文件夹中,然后从 /imports/ 导入.我知道他们说这只能在未来的版本中使用,但如果现在可以使用,我不会感到惊讶

Before you do that though, I would try symlinking the package from node_modules into your imports folder somewhere and importing from /imports/. I know they've said this will only work in future versions but I wouldn't be surprised if it can work now

这篇关于在 node_modules 中编译一个包在浏览器中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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