Best way of concatenating or merging files in node.js - javascript

So i've been searching for the best way of concatenate n (log) files in node.js
The final file cannot be more than 100MB, if there is more, i should create an other one and so on.
I have some different approaches:
Use grunt and grunt and https://www.npmjs.com/package/grunt-contrib-concat
Use a simple npm like buldify https://github.com/powmedia/buildify
Do it from scratch with the fs node.js module
I wonder if you could throw me some of your experience here and also this question could be useful for someone in the future.
Cheers!

Both grunt-contrib-concat and buildify were designed to concatenate JS source files into one bundle, so they are not fit for your task.
I would suggest using something like logrotate-stream instead.

Related

Custom NodeJS build including javascript modules

is it somehow possible to build NodeJS together with some selected JavaScript modules? I believe that for native modules, I should be able to achieve this with node-gyp, but I have no idea how to do this for JavaScript modules. The main idea is to be able to use custom application without npm install.
I know that I can use any of the bundlers like pkg or nexe, but this has some drawbacks with respect to the development...
Thanks!
You can include JS files as described in here.
Just add a link-module parameter.
> .\vcbuild link-module './myCustomModule.js'

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. 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. Is this even possible?
Yes it is completely posible... There are various ways of doing it..
With grunt: Try this contrib module. 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. 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. 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.

How do you build a node project into one file?

I have been creating projects using npm. For AMD I am using the native node require because it is convenient and does what I need it to do. To run my projects at the moment I am using grunt-watchify. This allows me to point a file of entry and a file of output. So at the moment it produces one file uncompressed or mangled.
I would like to know what is the best approach for compressing and mangling my final file. I have tried uglify after the file is built by watchify but it does not seem to work correctly. I feel that is a dirty hack anyway. So here is my questions?
What is the best way to build a node project into one file? Grunt library suggestions would be great. Any that support compression/minifying would also be great.
Thanks
Removed my dependency on grunt-watchify and now just use grunt-browersify and grunt-contrib-watch. I then use grunt-contrib-uglify and grunt-contrib-cssmin to minimize files afterwards.

`make` Javascript compiling/testing

Is there a library intended for compiling/testing your Javascript libraries?
I've noticed many common Javascript libraries like jQuery still use gnu make. Nothing is wrong with the traditional make, but I was just curious if a solution in Javascript has been crafted.
Obviously using node.js you can easily fs.readFile and then concat the files but it is often nice to look at others source who have more experience on the topic.
I believe your looking for Ender. It's a package manager for client-side javascript.
You define your package in your standard package.json file and then use the command line ender API to construct and build your javascript package.

Less like middleware for javascript files

I would like to have something like less but for javascript files. I know that grunt-contrib-concat do that thing, making .map file from many .js files. I don't want to use grunt to success that task. Do you know any other package? I have searched others without success.
Webpack or SystemJS would be my recommendation. Both will actually build your javascript, resolving dependencies and allowing you to use es6 or commonjs module loading. This is a more modern and preferred approach to simply concatenating files.

Categories

Resources