Webpack bootloader test for files without a specific part of the file name

I save my tests in the same folder as my components, and I try to apply the webpack loader ( istanbul-instrumenter-loader ) to all files except those named exactly spec.js or end with *Spec.js (so both components/SupportPage/spec.js and actions/SupportActionsSpec.js will not be included. I tried to get the correct RegEx on regextester.com, but I can not get it to work. Am I missing something?

+5
source share
2 answers

Ok, I found it. Writing a single test to include all files, but excluding specific specification files was probably the wrong approach, I solved it as follows:

  { test: /.\.js$/, exclude: /(node_modules|bower_components)\/|.[sS]pec\.js$/, loader: 'istanbul-instrumenter' } 
+4
source

I tried to solve a similar problem styleUrls Angular 2 styles imported through styleUrls . I thought that I would add my decision as a complement to the accepted answer for posterity.

This solution distinguishes styles of components that need to be loaded using to-string-loader , unlike other styles that can be loaded using style-loader .

If you configure the components as follows:

 @Component({ selector: 'admin', styleUrls: ['./admin.component.scss'], templateUrl: './admin.component.html' }) 

You can use the following rules:

 // For components `to-string-loader` { test: /\.css$/, use: ['to-string-loader', 'css-loader'], include: /\.component\.css$/ }, // For non-components `style-loader` { test: /\.css$/, use: ['style-loader', 'css-loader'], exclude: /\.component\.css$/ } 
0
source

Source: https://habr.com/ru/post/1239019/


All Articles