Home > Web Front-end > HTML Tutorial > How to clean expired hash files packaged by webpack on the server

How to clean expired hash files packaged by webpack on the server

不言
Release: 2018-09-17 14:28:10
Original
2081 people have browsed it

The content of this article is about how to clean up the expired hash files packaged by webpack on the server. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Nowadays, front-end projects basically use webpack to package code, and the file names (except html files) are hashed, which can remove the browser cache. But another problem will arise, that is, a large number of expired (will not be used) hash files will accumulate on the server. These files are mainly js and css files, because basically every build will generate new js and css files. If these files are not cleared, they will occupy a large amount of server storage space.

1. Idea

1. Read the hash value set of the css file from the html file;

2. Then based on these hash value sets, the hash is not in this set Delete the css files within;

3. Read the hash value set of the js file from the html file;

4. Then based on these hash value sets, put those that are not dynamically loaded, And js files whose hash is not in this collection are deleted; (Dynamic loading of js refers to dynamic-imports)

5. Read the hash value set of dynamically loaded js files from js files that do not belong to dynamic loading;

6. Then based on these hash value sets, delete the js files that are dynamically loaded and the hash is not in this set;

7. From the remaining html, css, js files Read the hash value set of other static resource files such as pictures and fonts;

8. Then based on these hash value set, delete the static resource files whose hash is not in this set.

2. sclean

Based on the above idea, I encapsulated an npm package: sclean.

Mainly has the following functions:

1. Back up server files, because deletion is a very dangerous operation, so you will back it up before clearing expired files. Of course, you can also back up manually;

2. Restore server files to a state that was previously backed up ( Used for recovery operations after clearing errors);

3. Perform clearing operations according to configuration, such as customizing the target directory (dist, build), html file (php, jsp), hash length (32, 8) wait.

Installation

npm install sclean -g
Copy after login

Perform cleanup operation

sclean
Copy after login

The above is the detailed content of How to clean expired hash files packaged by webpack on the server. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template