Search code examples
javascriptwindowsconcatenationbundling-and-minification

Merge multiple minified javascript files in recursive folders into one file


I have multiple minified files in multiple folder in a single folder for minified js.

I wish to create single js file from all of minified js. Now I am using type command to concatenate all files like

type .\\v2\\dist\\js\\*.js >> .\\build\\a.min.js   &&   type .\\v2\\dist\\js\\config\\*.js >> .\\build\\a.min.js && ... 

Like wise I need to append all recursive folders. Is there any clean way to do it.

Please don't suggest using Gulp or Grunt as we are already in process of removing them & using Webpack. Any code using webpack or using npm or simple command line is welcome.


Solution

  • If on Windows, you can use command line like below (refer to @dbenham's answer):

    for /r "c:\javascripts" %F in (*.js) do @type "%F" >>concatenated.js
    

    If on Linux or Mac, you can use find:

    find ./v2/dist/js/ -name '*.js' -exec cat {} \; > ./build/a.min.js