简体   繁体   English

是否可以使用ES6模块编写JS库,但仍然能够在NodeJS后端中使用它?

[英]Is it possible to write a JS library using ES6 modules, but still being able to use it in a NodeJS back-end?

I would like to write a JavaScript library using ES6 modules to manage submodules. 我想使用ES6模块编写JavaScript库来管理子模块。 I would also like to be able to use it in both front-end applications (with babel and webpack) and NodeJS back-end projects. 我还希望能够在前端应用程序(带有babel和webpack)和NodeJS后端项目中使用它。

Is there a way to "build" the library, written with ES6 modules, in order to use it also as a NodeJS library? 有没有一种方法可以“构建”用ES6模块编写的库,以同时将其用作NodeJS库?

I believe this question is related with Webpack for back-end? 我相信这个问题与Webpack后端有关吗?

But yes, it is possible. 但是是的,有可能。 You just need to install babel and webpack and then you will be all set 您只需要安装babel和webpack,然后一切就绪。

Yes! 是! webpack supports both node and web targets! webpack支持nodeweb目标! You can find more information about how to set this in your config at webpack.js.org/configuration/target 您可以在webpack.js.org/configuration/target中找到有关如何在配置中进行设置的更多信息。

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

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