Using ignorePlugin to ignore one folder from dependencies. - javascript

I've realized that one of a big folder inside one of my dependencies is not required. But since it takes almost 30kb of my build size, I wish to ignore it from the final webpack build. For that, i'm trying to use the webpack ignorePlugin.
This is what i've tried till now:
new webpack.IgnorePlugin(/^\.\/precomputed$/, /elliptic$/),
The absolute path for the folder that I wanna ignore is :
node_modules/elliptic/precomputed
What i'm doing wrong here ? Is there anything else required ? Thanks for help ! Appreciate it :)

The regular expressions you're using don't match the path of the module.
/^\.\/precomputed$/ matches only exactly ./precomputed. Because it's using the beginning of string ^ and the end of the string $, and in between is only ./precomputed.
/elliptic$/ matches every string that ends in elliitic.
The correct regular expression for your module would be:
/elliptic\/precomputed$/
But this matches only the modules that end in elliptic/precomputed (because of the $ anchor). For instance elliptic/precomputed.js or elliptic/precomputed/submodule are not matched. If you intend to include these as well you can remove the $ and it will match all of them:
/elliptic\/precomputed/
Try it in Regexr, when you add $ to the pattern you'll see that only the first one matches.

Related

there is no char between 2 group with regex

I need a regexp to filter a list of paths.
my sample list is below:
models/user.js
models/adapter.js
models/acquire.js
models/schema/extension.js
models/schema/permission.js
modules/breaktime/models/break.js
modules/breaktime/models/rule.js
modules/breaktime/models/step.js
modules/pbxmanager/models/group.js
modules/pbxmanager/models/member.js
modules/pbxmanager/models/shift.js
modules/breaktime/models/request.js
modules/breaktime/models/state.js
I'd define the exact start path and want to get only the files under that path, not from subfolders.
For example; if I set models/ as a starter string in the regexp, I should only get first 3 line, not those under schema folder.
I tried to make groups like (^start string)(exactly nothing)(end string$) but no luck.
(^models\/)[\w{0}](\/[\w]+\.js$)
https://regex101.com/r/wNtCni/1
I couldn't find how to set "nothing between two group" in regexp.
If you use a character class [\w{0}] there is at least a single char expected, either a word character, {, 0, or }
In your case you don't want that and you can omit it the character class which will give you (^models\/)(\/[\w]+\.js$) which has a forward slash too much.
If you remove that extra / as well, and remove the unnecessary groups and brackets, you will get
^models\/\w+\.js$
Regex demo

regex match extension but exclude a specific file

I am in webpack.config where I need to include extension to match specific file type, but I need to exclude a specific file. I googled it but didn't find a perfect solution.
What I have : /\.(?:css|less)$/ -> matches all files that have .less OR .css but here I want to add "not only -> test.something_strict.less" /\.(?:css|less|!test.less)$/ where test.something_strict is a file name with extension .less and only exclude test.something_strict
but this didn't work, this matches .less or .css and pass through the test.
|!test.less doesn't really negate matching test.less. It will literally match ! before test.less.
You can use this regex:
/^(?!test\.[^.]+\.less$).+\.(?:css|less)$/m
RegEx Demo
(?!test\.less$) is a negative lookahead that will assert failure if filename is test.<anything>.less.

Search and replace moduleFor('foo:bar') with moduleFor('foo:bar', 'unit#foo:bar')

I am working with a large set of qunit unit tests in a folder called "tests". At the top of each file is the following, for example:
moduleFor('mixin:foo')
// or
moduleFor('route:bar')
I'd like to write a search and replace for these files such that each occurrence would be replaced with this updated style:
moduleFor('mixin:foo', 'unit#mixin:foo')
// or
moduleFor('route:bar', 'unit#route:foo')
If the first line of your file is this line, you can use this, with multiline flag on.
\AmoduleFor\('(.*?)'\)$
Where \A always matches the beginning of the input data (file in this case). $ because of the multiline flag, matches the end of the line (not the input). You can also probably remove the $ in case of following whitespace or comments you don't want to affect. If this is always the total first line, I'd leave the $.
In this example here, I deliberately use ^ to match the beginning of the line rather than the input, merely for demonstration purposes.
I'm not familiar with qunit and if there might be no other occurences of module in the file, if there is not, assertions shouldn't be necessary.

Javascript - regex to check if user write correct formated input

in my CLI users can specify what they want to use:
A user command can look like this:
include=name1,name2,name3
category=name1,name2
category=name1
In another words, a command always consists of 3 parts:
command name: can be just include or category
=: is in every command
name or names of things they want to use, split by ,
How can I test this to get always true but false on everything else.
I am really bad in regex but I tried something like this:
/\category|include=\w/.test(str);
to simply test, at least, the most easy alternative which would be category=name1 but without success.
Can someone help me with this?
You were on the right path. Here's a fixed regex:
/^(category|include)=\w+(,\w+)*$/.test(str);
Note:
the parens around the alternative parts
the + after the \w so that you can have several characters
the optional (,\w+)*
the start and end of string marks (^ and $) in order to check the whole string
You can use this regex for your requorement:
/^(category|include)=(\w+(?:,\w+)*)$/
RegEx Demo
\w+(?:,\w+)*) in the value part after = will allow 1 or more of comma separated words.

Window Location Pathname with Multiple Directories

I'm sure this very easy, but I am having trouble writing this path correctly. I have no problems triggering the command using:
if(window.location.pathname.match(/^\/Home-Blog/)) {$('#maincolumn').remove();}
But for another case, I need the pathname to be longer, with the following directory:
/Home-Blog/CategoryBlogID
Any way I try to insert it, it doesn't seem to work. How do I plug in the path to "CategoryBlogID"?
Thank you!
I'm not totally sure I understand your question, but if you want to match
/Home-Blog
/Home-Blog/
/Home-Blog/CategegoryBlogID
this RegExp should do the trick:
"/Home-Blog/CategoryBlogIDs".match(/^\/Home-Blog(\/)*(CategoryBlogID)?$/)
/^ start of string
\/ a forward slash
Home-Blog the text "Home-Blog"
(\/)* a forward slash zero or more times (will also match /Home-Blog////CategoryBlogID) because of this
(CategoryBlogID)? the string "CategoryBlogID" zero or one times
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#grouping-back-references

Categories

Resources