N
N
Nazariy Lazarchuk2020-07-24 19:48:45
webpack
Nazariy Lazarchuk, 2020-07-24 19:48:45

How does searching for files by string work in Webpack?

I have a task to remove unused files from the project.
Given: `app` folder, it contains files:
*.js, *.jsx, *.ts, *.tsx
and tests: *.test.js, *.test.jsx.
I'm using the `unused-files-webpack-plugin` plugin, where I have to specify the PATH of the files to be checked:

{ patterns: ['app/**/*.js', 'app/**/*.ts', 'app/**/*.jsx', 'app/**/*.tsx'] }

in this case, it finds absolutely all files, but I need the test files to be ignored.
Also, I don't understand what the `app/**/*.js` pattern is, because it's obviously not a regular expression, and how to make the `*.test.js` files be ignored.
Please post info on this! Thank you in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nazariy Lazarchuk, 2020-07-27
@LazarchukNazar

This pattern is handled by the node-glob library ( https://github.com/isaacs/node-glob#glob-primer ), which in turn creates a search regular expression based on the Glob Primer.
I don't understand why it is needed. Apparently, for programmers who do not learn regular expressions =)
Or make it easier to write paths (IMHO declarative)
example:

/^app\/.+[jt]sx?$/g; // регулярка
'app/**/*.[jt]s{,x}'; // node-glob шаблон

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question