简体   繁体   English

如何在不泄露代码的情况下将包发布到 npm

[英]How to publish package to npm without revealing the code

I'm trying to publish package to npm but don't want that who using the package be able to see the code.我正在尝试将包发布到 npm,但不希望使用该包的人能够看到代码。 How can I do this?我怎样才能做到这一点?

Since npm is pretty much used to distribute JavaScript+CSS files, there is nothing you can do about it.由于npm几乎用于分发 JavaScript+CSS 文件,因此您无能为力。 Your code is going to be seen by whoever uses it or executes it.您的代码将被使用或执行它的任何人看到。

You might be able to mitigate this somehow by using minifiers or obfuscators though.不过,您可以通过使用缩小器混淆器以某种方式缓解这种情况。

You can compile your code eg to dist folder and then run npm publish in the dist directory.您可以将代码编译到dist文件夹,然后在dist目录中运行npm publish Users then can see only what will be placed in the dist folder (compiled code).然后用户只能看到将放置在 dist 文件夹中的内容(编译代码)。 However, I think that this is not good practice.但是,我认为这不是一个好的做法。

You can also consider private npm packages to distribute your packages only to those who you want.您还可以考虑使用私有 npm 包将您的包仅分发给您想要的人。

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

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