Jackie
Jackie

Reputation: 23607

How to use specific loaders for a specific file using webpack

I have a situation where I would like all stylus files to use the webpack loaders...

{
      test: /\.styl$/,
      loaders: ["to-string", "css", "stylus"]
},

but on global style files (ones ending in .global.styl), I would like to use a different set of loaders...

loaders: ["style", "css", "stylus"]

I tried the following...

 {
      test: /.*(?<!global)\.styl$/,
      loaders: ["to-string", "css", "stylus"]
 },

But it didn't work...

SyntaxError: Invalid regular expression: /.*(?<!global)\.styl$/: Invalid group

Upvotes: 0

Views: 574

Answers (1)

Hosar
Hosar

Reputation: 5292

You can try with not a ^ as follow:

// First case: someFiles.styl ending with .style
{
      test: /.*[^\.global]\.styl$/,
      loaders: ["to-string", "css", "stylus"]
},
// Second case: someFiles.global.styl ending with .global.styl
{
      test: /.*[\.global]\.styl$/,
      loaders: ["different", "loaders", "stylus"]
},

Upvotes: 1

Related Questions