简体   繁体   English

是否可以在NPM包中为浏览器和服务器(NodeJS)定义不同的位置?

[英]Is it possible to define different locations in your NPM package for browser and for server (NodeJS)?

Is it possible to define different locations in your NPM package for browser and for server (NodeJS)? 是否可以在NPM包中为浏览器和服务器(NodeJS)定义不同的位置?

My code is largely isomorphic, but it is uglified and concatenated for browsers. 我的代码在很大程度上是同构的,但是对于浏览器来说却是丑陋的,而且是串联在一起的。

Short answer, is that you can't do such thing. 简而言之,就是你不能做这样的事情。 Mostly your dependencies are stored under /node_modules folder. 通常,您的依赖项存储在/node_modules文件夹下。

You may override this option by running some patches or an installer script. 您可以通过运行某些补丁程序或安装程序脚本来覆盖此选项。 Here is a bug raised on Github about this issue.It's is also described in an official NPM blogpost 这是Github上有关此问题的错误 ,在NPM官方博客中也有描述

But don't feel disappointed, you may use Bower as a dependency injector for your client side code. 但是不要失望,您可以将Bower用作客户端代码的依赖项注入器。 I prefer it as it feels more semantically and separated: Bower for the front end, NPM for the back end. 我更喜欢它,因为它在语义上和分离感方面更高:Bower代表前端,NPM代表后端。

Moreover, NPM packages are built for CommonJs only, Bower packages instead are more plug and play solutions 此外,NPM软件包仅用于CommonJs,而Bower软件包则是更多的即插即用解决方案

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

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