In-depth understanding of the Glob model and its application in development
The Glob (Global) model is a simplified regular expression syntax, originally used for Unix Shell Matches the file path. Now it's an integral part of the modern Web development tool chain, and it's used extensively.
Webpack, Gulp, ESLint, Prettier, VS Code
and types of CI/CD profiles (e. g.
.gitignore
and
GitHub Actions
I'm not sure.
Why use the Glob test tool?
In complex project structures, it is extremely challenging to develop precise path matching rules. Common pain points include:
-
Error matching sensitive files:
A mistake.
**/*.jsIt could be accidental to includenode_modulesor production environmentsecrets.jsIt leads to slow construction and even security loopholes. -
The exclusion rule is invalid:
!Negative mode is different (e.g.picomatchvsminimatchThere are minor differences in behaviour in the ) which result in the configuration not being effective. -
Retrogressive performance bottlenecks:
Overuse
**This will result in the scanning of tens of KiloCell of unrelated documents, significantly slowing down the CI/CD process.
Our online tester passed. picomatch Engine (one of the most efficient current Glob resolutionrs) provides real-time feedback matching to help you to apply the configuration before it is refined.
Specific scenes to be addressed
Scenario one: Configure the Lint rules.
You wish.
src
All of it.
.js
and
.ts
File check, but exclude all by
.test.
. You can test mode:
src/**/!(*.test).{js,ts}
。
Scenario 2: Webpack entrance scan.
Pass.
**/*.entry.js
Automatically discover all entry files to ensure that pages under the embedded directory are properly packed.
Scenario 3: CI/CD cache path.
Configure in GitHub Actions
cache
Path, make sure you only cache
package-lock.json
is the directory where you want to avoid the cache of redundant data.
Glob core grammar details
-
*(Single asterisk): Matches any number of characters in a single path segment. For example:*.jsMatchapp.js, but not matchedsrc/app.js。 -
**(Dual asterisk): Matches zero or more directories. For example:src/**/*.jsDepth recursively.srcBelow all JavaScript files. -
{}(Bracketed): to create an extension group.{js,ts}MatchjsortsSuffix. -
[](in parentheses): Matches the character set.[0-9]Matches any digital bit. -
!(Exclaims): For taking the reverse. Note that in many cases, the counter-model usually needs to be placed at the end of a list or as a separate rule.
How to use this tool?
1. Input mode: Enter your Glob rule in the left input box. Tools will automatically parse and generate human-readable syntax descriptions for you.
2. List path: Pastes your project document structure (parts) to the bottom text box. The proposal contains some critical paths that you want to match and exclude.
3. Observation feedback: The right side displays results in real time through the green (match) and grey (not match) labels and counts the hit rate.
4. Share: Click on the Sharing Test to generate encrypted links with the current configuration to facilitate discussion or recording of the configuration with colleagues.