Vue-webpack Project automatic packing compressed into zip file batch processing

Source: Internet
Author: User
Tags custom name

Why do you need this?

Using the Vue Framework Development project, the NPM Run build command will always be used, if you need to send a back-end package, then you have to package into a zip format of the compression packet, especially when the project is measured, the day may be repeated several times, so the impulse to write this batch process.

I haven't written it before, but I've used it at least. Find a batch of orders to understand the article, according to their own pre-thought good idea, Baidu has the key to execute the command, and then on their own continuous modification debugging, finally completed the set Webpack packaging, compressed into a zip format file, open the current folder three functions of the batch processing.

How to use it?

Just put this batch file in the project root directory, easy, and so on after the command to run the open folder, you can directly copy the packaged compressed package to the back-end personnel.

Full code:

Title Project automatic packaging and Compression batch processing toolCLS@echo ifEcho┌────────────────────────────────────┐Echo.EchoVue+Webpack Project automatic packaging and Compression batch processing toolEcho.EchoAuthor: Cuichunhua@qq.comEcho.Echofunction Description:Echo.Echo1.vue+webpack Project Automatic packagingEcho.Echo2.automatically compresses to zip file after packaging is complete, custom nameEcho.Echo3.compression complete, automatically open the current folder in ExplorerEcho.Echo└────────────────────────────────────┘Echo.REM1. Vue Project PackagingEchopackaging is about to be processed later ... Echo.PagerNpmRunBuildREMThe return code >=1 jumps to the header 1 to perform the compression, >=0 jumps to the heading exit to perform the terminationIF ERRORLEVEL1 (EchoProject Packaging error, go and see what's going on!!! Echo.Goto Exit)IF ERRORLEVEL0 (Echopackage complete, auto-compress ... Echo.GotoZip)REM2. Automatically compress into a zip file, and in CODE_YYMMDDHHMMSS format: ZipEchoStart compressing files ... Echo.CD/D DistREMpackage into a zip format file will need to WinRAR.exe, or will be reported "unknown option: Afzip"SetRar=%programfiles%\winrar\winrar.EXESetname=code_%Date: ~0,4%%Date: ~5,2%%Date: ~8,2%% Time: ~0,2%% Time: ~3,2%% Time: ~6,2%(EchoStaticEchoindex.html) >r.LST"%rar%" A-afzip "%name%.zip"-EP1-RR-AV-AO-M5 @r.lst-ibck-xr.LSTdelR.LSTGoto2REM3. Open the current folder automatically: 2Echocompression complete, automatically open the current folder ... Echo.Explorer%CD%Goto ExitREM4. Terminate the command to continue execution: ExitPause

Code Description:

The batch process consists of three processes:

1. Vue Project Packaging;

1) Use call to execute NPM run build, so that the package processing will not automatically exit the command line window, subsequent commands can be executed, remember.

2) Processing result processing:

IF ERRORLEVEL 1 (    echo   Project Packaging error, go and see what's going on!!!     echo.      Goto exit) IF ERRORLEVEL 0 (    echo   pack complete, auto compress ...     echo.      Goto zip)

Remove the excess code, the upper code can be reduced to:

IF ERRORLEVEL 1 goto exit

IF ERRORLEVEL 0 goto Zip

This code means: If the previous command failed, execute the EXIT command block and execute the ZIP command block successfully.

which

    • ERRORLEVEL results for the previous command, returns 0 successfully, and fails by default returns 1;
    • If ERRORLEVEL 1 means if ERRORLEVEL >= 1, so the command to judge the failure should be placed before the command to determine the success, do not reverse, remember!
    • Exit, zip can be understood as a command block, like the function code block in JS, this command block is defined by: the beginning, such as: Exit, this is a simple command block;
REM 4. Terminate the command to continue execution : ExitPause

2. Compress into a zip file;

The key code here is as follows:

CD/D Dist
Set Rar=%programfiles%\winrar\winrar. Set name=code_%date: ~0,4%%date: ~5,2%%date: ~8,2%%Time: ~0,2 Percenttime: ~3,2%%time: ~6,2%(echo static echo index.html) >r.lst"%rar%" A-afzip "%name%.zip"-EP1-RR-AV-AO-M5 @r.lst-ibck-xr. del r.lst

which

    • Set Rar=%programfiles%\winrar\winrar.exe Obviously, this line of code is to define the compression program variable;
    • Set name=code_%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2% This line defines the compressed file name, the default Code_ YYYYMMDDHHMMSS format, can be modified according to the needs of their own,%date:~0,4% to intercept the local date of the year,%time:~0,2% for the interception of the time of the hour, remember the wording, you can use JS intercept string to aid understanding;
    • The following line is the specified leader directory or file:
    • (Echo static echo index.html) >r.LST
    • -afzip is compressed into a ZIP file (with the RAR variable to point to WinRAR.exe only takes effect)
    • "%name%.zip" is named after the variable name

3. Open the current folder (Dist)

Explorer%cd% open the current folder in Explorer to send compressed packaged files to other developers

Vue-webpack Project automatic packing compressed into zip file batch processing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.