Node glob pattern for every .js file except .spec.js - javascript

I am looking for a better glob pattern for usemin, i want to to find all .js files but exclude the .spec.js files. I have the following solution so far.
<script src="components/**/*(.js|!(*.spec.js|*.scss))"></script>
The solution i have at the moment requires me to keep adding file extensions to exclude them, else they get picked up, for example .html files.
I tried to make it only look for .js files and exclude the .spec.js from them but it does not seem to work.
Also adding a !components/**/*.spec.js as another script below does not seem to work.

This glob includes all *.js but not *.spec.js:
components/**/!(*.spec).js

Related

How to exclude only *.spec files and include all other *.js files under a directory in grunt task?

I need to include all *.js files and exclude only *.spec.js files under a directory.
I tried the following ways, it's either including all js or excluding all js files
'built/code/js/libs/preact/**/!(*.spec).js') but it fails with the message syntax error near unexpected token `('.
If I do this way - 'built/code/js/libs/preact/**/!*.spec.js') it excludes all js files
If I add in 2 different lines like below it excludes all js files
('built/code/js/libs/preact/**/*.js' +
'built/code/js/libs/preact/**/!*.spec.js')
Please let me know if there's a way to exclude spec files and include all other js files.

Webpack - Bundle files in a specific sequence

I would like to concatenate my .css and .scss files in a specific order.
For example, I'd like to be able to specify the first file in my build process and move to other directories when that is complete (1st .scss files then .css files). In the end, I'd like to have generated a single .css file
I'm just looking for some guidance on where to go and what to read (more specific to my situation) in order to figure this out. I've done a bit of research and haven't found a solution or someone who has tried to do that before.

How to copy files from exact folder which is positioned somewhere in a folder structure using gulp

I'm wondering is there a way to solve this problem:
I would like to copy all fonts from bower_components to .tmp/assets/fonts, but the problem is that some fonts are .svg, so if I do it in a regular way using this code:
gulp.task('copyBowerFonts', function(){
return gulp.src("bower_components/**/*.{ttf,woff,eof,svg}")
.pipe(gulp.dest(paths.tmpFonts));
});
... i will get all font files along with .svg files, so the mentioned peace of code will also copy images with .svg extension and put them into the .tmp/assets/fonts . So if i could say ok, copy everything from fonts/ within any folder to the desired location it would be great.
I will also use gulp-flatten to copy just files without their folder structure.
So, finally, is there an option like, or how could this work?:
gulp.src("bower_components/**/fonts/*.{ttf,woff,eof,svg}"
I assume that solution is simple, but I couldn't find it so far.
Thanks for the help. :)
The pattern you wrote should work for you.
Keep in mind that Gulp uses glob module:
* Matches 0 or more characters in a single path portion
** If a "globstar" is alone in a path portion, then it matches zero or more directories and subdirectories searching for matches. It does not crawl symlinked directories.

r.js - excluding specific list of files

Hello evryone,
I'm trying to find a way to make the r.js not to copy all the files form my /lib/ directory except for (for example) jquery.js and require.js.
I'm using fileExclusionRegExp option to exclude all *.js files except for the above mentioned.
fileExclusionRegExp: '\/lib\/(?!jquery|require).*\.js'
But after the optimization, I can still see that other files have been copied over too.
Is there anything I'm doing wrong ? Or is the regex incorrect?
Thanks in advance
The problem you've run into is that you are trying to make fileExclusionRegExp match the entire path of a file, but r.js uses it only to test against the base name of files. You can infer this from the description of the option and its default value. The description says:
//When the optimizer copies files from the source location to the
//destination directory, it will skip directories and files that start
//with a ".".
The default value is:
/^\./
If this were to be tested against a full path, it would not be able to exclude files that start with a period if they are in a subdirectory. We also find confirmation of this behavior in this issue report.
If you have only one file named require.js and one file named jquery.js, then you can get by with this regexp:
fileExclusionRegExp: /^(?!jquery|require).*\.js$/
Otherwise, fileExclusionRegExp is not going to do it, and you should use a build step to clean your directory, as suggested by the author of RequireJS in the issue report I mention above.

Gulp: running through all dependencies without duplicating?

gulp.task("compile-vendor-js", function() {
return gulp.src("./bower_components/*/*.js")
.pipe(concat("vendor.js"))
.pipe(gulp.dest("./build"))
});
This gulp task will compile bower solved dependencies.
The problem is, it will consider all JS files, including the minified ones, making my build file have duplicated code.
I know that one solution for this is having a variable array containing all file paths, but this isn't good.
try something like:
gulp.src(["./bower_components/*/*.js", "!./bower_components/*/*.min.js"])
where you can find a common denominator between all the minified js files (eg, .min.js)
I think that a blacklist of files is going to be shorter than a whitelist in this case.
Also, you might consider looking into the main-bower-files project, which will read your bower.json file and pull out the main js files from each project for you.

Categories

Resources