简体   繁体   English

NPM:依赖于本地 ES6 模块(无转译)

[英]NPM: Depending on a local ES6 module (without transpiling)

I'm developing two npm modules locally, A and B, and A has B as its dependency.我正在本地开发两个 npm 模块,A 和 B,A 有 B 作为它的依赖项。

To facilite development I'm using npm link to symlink package folders;为了促进开发,我使用npm link到符号链接包文件夹; so inside A's node_modules there is a symlink to B's project folder.所以在 A 的 node_modules 中有一个指向 B 项目文件夹的符号链接。

When starting up A by running node --harmony the runtime complains about B using ES6 language features.通过运行node --harmony启动 A 时,运行时会抱怨 B 使用 ES6 语言功能。 However, A's own usage of ES6 language features is fine.不过,A 自己对 ES6 语言特性的使用是没问题的。

How can I use a non-transpiled ES6 module as a dependency?如何使用非转译的 ES6 模块作为依赖?

Not sure about your eventual goal, but when I develop a module I need (or other people need) to depend on, I place an es5 file in the dist folder, and depend on that.不确定你的最终目标,但是当我开发一个我需要(或其他人需要)依赖的模块时,我将一个 es5 文件放在 dist 文件夹中,并依赖于它。 This way the es6 file stays for developing purposes and the es5 file is generated dynamically by babel for consumption.这样 es6 文件保留用于开发目的,而 es5 文件由 babel 动态生成以供使用。

So just like you're using babel to transpile your A module, I'd do the same for the B module and depend on that.所以就像你使用 babel 来转译你的A模块一样,我会对B模块做同样的事情并依赖于它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM