简体   繁体   English

用咕unt声将功能的多个部分合并并合并到一个文件中

[英]Concat and uglify multiple parts of a function into one file with grunt

So I have a node project with a javascript file that contains a huge function that has alot of code. 因此,我有一个带有javascript文件的节点项目,其中包含一个包含大量代码的巨大函数。 I was wondering if I could breakup this standard javascript function, into seperate functions and have grunt "compile them" into 1 function in 1 file. 我想知道是否可以将此标准javascript函数分解为单独的函数,并在1个文件中将它们“编译”为1个函数。 Is this even possible? 这有可能吗?

Yes it is completely posible... There are various ways of doing it.. 是的,它完全可能。有多种方法可以做到。

With grunt: Try this contrib module . 格外苦恼:尝试这个contrib模块 It is very easy to use and all the documentation is detailed in the link. 它非常易于使用,并且链接中详细介绍了所有文档。

Without grunt: On the other hand if you want to try something without grunt you could try the selectizer module. 没有咕 gr 声:另一方面,如果您想尝试一些没有咕unt声的东西,则可以尝试选择模块。 If it fits your needs I think that this is a much better option given that you can arrenge your dependecies explicitly using the requireJs syntax and then compile all the modules into one single clean file. 如果满足您的需求,我认为这是一个更好的选择,因为您可以使用requireJs语法显式地破坏您的依赖关系,然后将所有模块编译到一个单独的干净文件中。 That makes your code easier to maintain in the mid-term/long-term. 这使您的代码在中期/长期中更易于维护。 Also you could select which modules to build and which not, so in the final build there are going to be only the module you selected and their dependencies and no more. 另外,您可以选择要构建的模块,而不是要构建的模块,因此在最终构建中,将仅包含您选择的模块及其依赖性。

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

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