我们可以从压缩的“zip”文件运行我们的node.js项目而不提取Zip文件吗?

时间:2017-06-15 07:27:06

标签: node.js

根据客户要求,项目规模应该较小。但生成的源代码大小远远高于客户端需求。所以这个问题提出了我们如何从zip文件中运行node.js项目而不提取它们。有什么解决方案吗?请帮忙。谢谢你。

2 个答案:

答案 0 :(得分:0)

在初始帖子之后添加:尚未可以运行压缩代码。

您是否考虑过缩小项目的代码?

有些包压缩js和css文件。他们甚至将它们连接成单个js和单个css文件用于部署。这将减小文件大小,并且会加快页面加载速度,因为您的应用程序将减少对服务器的请求。

如果你想用缩小器做到这一点:https://github.com/mishoo/UglifyJS2 如果您想手动完成:http://prettydiff.com/?m=minify

另外,看看webpack。我没有亲自使用它,但它被描述为做同样的事情。它为您捆绑您的项目。 https://webpack.js.org/

答案 1 :(得分:0)

You could try this approach, which will work if you're running on any Unix based system:

First, you need to combine your js source files into a single file. You could use a minifier to do this, or just cat them into one file.

Next, compress the file, e.g. gzip <src.js>. This will produce a compressed file like scr.js.gz.

You can now run this file using a command line like this: gzip -cd src.js.gz | node. What the command is doing is (1) unzipping the source file (-c) and writing the result to stdout (-d), and (2) piping the code to node, which will run it in interactive mode.

One caveat here is that, same as any other node app, any external dependencies in your code will need to be installed using npm before hand. If this is not possible in the target environment then you will need to remove those dependencies, perhaps by incorporating module code directly into your source.