如何获得另一个依赖的依赖?

[英]How to get a dependency of another dependency?


I have a package (babel-preset-es2015-webpack) with dependency babel-preset-es2015. babel-preset-es2015 have dependency babel-plugin-transform-es2015-modules-commonjs.

我有一个包(babel-preset-es2015-webpack)与依赖babel-preset-es2015。 babel-preset-es2015有依赖性babel-plugin-transform-es2015-modules-commonjs。

How do I require babel-plugin-transform-es2015-modules-commonjs in a way to make sure that it is the same package that my babel-present-es2015 dependency is using?

我如何要求babel-plugin-transform-es2015-modules-commonjs以确保它与我的babel-present-es2015依赖项使用的包相同?

Simply doing:

简单地做:

require('babel-plugin-transform-es2015-modules-commonjs');

Will work in NPM3 setup (assuming there are no other dependencies that require a different version of babel-plugin-transform-es2015-modules-commonjs), but will not work in NPM2.

将在NPM3设置中工作(假设没有其他依赖项需要不同版本的babel-plugin-transform-es2015-modules-commonjs),但在NPM2中不起作用。

1 个解决方案

#1


1  

If you do not want to use shrinkwrap as noted by @Nocturno, you can also simply require the specific path to the dependency:

如果你不想使用@Nocturno所指出的shrinkwrap,你也可以简单地要求依赖的特定路径:

require('<path-to-node_modules>/babel-preset-es2015-webpack/node_modules/babel-plugin-transform-es2015-modules-commonjs');

Never used the plugins myself, but something like the above should work.

从来没有使用过插件,但上面的内容应该可行。

Another option is to lock down babel-preset-es2015-webpack to a specific version, then determine what version of babel-plugin-transform-es2015-modules-commonjs is listed in it's package.json and add it to your package.json. Then you can use the require('babel-plugin-transform-es2015-modules-commonjs'); method in NPM2 and NPM3.

另一个选择是将babel-preset-es2015-webpack锁定到特定版本,然后确定它的package.json中列出了哪个版本的babel-plugin-transform-es2015-modules-commonjs并将其添加到package.json中。然后你可以使用require('babel-plugin-transform-es2015-modules-commonjs'); NPM2和NPM3中的方法。

关注微信公众号

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2016/01/07/1d890c9ff7a694f28047062c0983cc7b.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com