In the project development environment, we will make the JS code as modular as possible, which is convenient for management and modification, which will inevitably lead to a project's own JS file number of 10 or more.
After the project is launched, it will be required to merge all JS files into 1 or several. Although manual operations are not a problem, it must be manually merged every time you modify and update, which is definitely a nightmare.
In this case, some tools will also arise, such as online merging, some websites provide js file upload, and then merge, but this is still very troublesome. What if the development environment does not have a network?
Then I thought of the copy command in cmd under the Windows system. Although it is a copy function, it can actually realize the need to merge files. Let’s take a look at this code below:
copy ++ /b
I believe that not many people who program will be able to roughly understand the meaning of reading the above code: merge point into one through the copy command, and the last /b means that the file is a binary file. Other parameters of the copy command can be entered into copy /? in cmd to learn, so I will not explain it in detail here.
Speaking of this, Windows itself can actually meet our needs and there is no need to install any other tools. What we need to do next is to make all this easier.
We create a new TXT file in the folder where the project stores JS, copy the code in, and modify which files need to be merged. Finally, save and modify TXT to BAT suffix, such as:
copy +++++++++++++++++++++ /b
Next, we double-click on the BAT file and see the effect? That's what we want. In the future, before going online, just double-click on this file, and the system will automatically merge and generate a merged file. Compared with other tools, this efficiency is simply impossible to see directly.
If you have installed the UglifyJS tool locally, you can add a compressed code after the code, such as:
copy +++++++++++++++++++++ /b
uglifyjs -m -o
In this way, it will automatically compress after each merge, saving another step of operation.
The same applies to CSS mergers.