Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webpack regex test for .js & .jsx

I'm using webpack and wondering if there is a way to determine .js or .jsx file extensions with the test regex?

i.e.

test: /\.jsx?$/

Would this work?

like image 344
Bryce Snyder Avatar asked Jan 24 '17 18:01

Bryce Snyder


Video Answer


2 Answers

Yes. test: /.jsx?$/ should be the right way. But you also need to set resolve.extensions parameter to make it work.

module.exports = {
  ...
  resolve: {
    extensions: ['.js', '.jsx']
  }
  ...
}
like image 134
Ruslan Shashkov Avatar answered Oct 08 '22 14:10

Ruslan Shashkov


i know this is very old question but i had like to share my solution.

solved it like this

test: /\.(js|mjs|jsx|ts|tsx)$/,

so, .js & .jsx or ts, tsx and mjs

these all extensions are going to be match. Much more elegant. May it help someone.

like image 23
Danish Avatar answered Oct 08 '22 12:10

Danish