简体   繁体   English

如何将节点项目捆绑到一个文件中

[英]How to bundle node project into one file

Is there any WORKING way how to bundle node project into one single file (including dependencies) and how? 有什么工作方式如何将节点项目捆绑到一个文件中(包括依赖项)以及如何?

I am using babel ( .babelrc ) 我正在使用babel( .babelrc

{
    "presets": ["@babel/preset-env"],
    "plugins": [
        [
            "module-resolver",
            {
                "root": [
                    "./src"
                ],
                "alias": {
                    "test": "./test",
                    "underscore": "lodash"
                }
            }
        ]
    ]
}

the answer is no. 答案是不。 babel can not do what you want by itself. 通天塔不能自己做你想要的。 It is a tool for transforming one dialect of Javascript into another, based on rules defined in your .babelrc file. 它是根据.babelrc文件中定义的规则将Java语言的一种方言转换为另一种方言的工具。 It is a compiler, not a linker (to borrow terms from the C world). 它是一个编译器,而不是链接器(从C语言世界借用术语)。

Using babel-plugin-module-resolver will not cause babel to transpile dependencies as if they were source files. 使用babel-plugin-module-resolver不会导致babel像依赖源文件一样转译依赖项。 It is simply a babel rule which modifies the paths passed to require() or import . 这只是一个babel规则,它修改了传递给require()import 的路径

To include dependencies as well as source files you need to use both a compiler like babel and a bundler such as webpack or rollup . 要包括依赖项和源文件,您需要同时使用babel这样的编译器和webpackrollup这样的捆绑程序。

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

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