如何将多文件node.js应用程序转换为单个文件? [英] How can I convert a multi-file node.js app to a single file?

查看:101
本文介绍了如何将多文件node.js应用程序转换为单个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个node.js应用程序,其中填充了许多 require 语句,如何将其编译为单个 .js 档案?我必须手动解析 require 语句,并确保以正确的顺序加载类。是否有一些工具可以做到这一点?

If I have a node.js application that is filled with many require statements, how can I compile this into a single .js file? I'd have to manually resolve the require statements and ensure that the classes are loaded in the correct order. Is there some tool that does this?

让我澄清一下。

在节点上运行的代码.js不是特定于节点的。 only 我正在做的事情没有直接的浏览器等效使用 require ,这就是我要问的原因。它没有使用任何节点库。

The code that is being run on node.js is not node specific. The only thing I'm doing that doesn't have a direct browser equivalent is using require, which is why I'm asking. It is not using any of the node libraries.

推荐答案

你可以使用带有target:'node'的webpack,它会内联所有必需的模块并将所有内容导出为单个,独立,一个文件,nodejs模块

You can use webpack with target: 'node', it will inline all required modules and export everything as a single, standalone, one file, nodejs module

http://webpack.github.io/docs/configuration.html#target

这篇关于如何将多文件node.js应用程序转换为单个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆