rails / webpacker

Use Webpack to manage app-like JavaScript modules in Rails
MIT License
5.31k stars 1.47k forks source link

How do I allow a package in node_modules to be processed by babel? #3258

Closed brandoncc closed 2 years ago

brandoncc commented 2 years ago

Hello,

I posted in the webpacker forum but I haven't gotten any responses, so I am trying here (I realize that it has been asked for us to use the forum, but I really need an answer, sorry).

I need to process one package with babel. The docs talk about a node_modules loader, but it isn't present in the gem anymore. How do I allow babel to process @react-spring? This is how I used to do it (webacker 3):

const babelLoader = environment.loaders.get('babel');
const babelLoaderUsed = babelLoader.use.find(
  (el) => el.loader === 'babel-loader'
);

babelLoader.test = /\.(js|jsx|ts|tsx)?(\.erb)?$/;

babelLoader.exclude = /node_modules\/(?!(@react-spring)\/).*/;

Thanks!

msencenb commented 1 year ago

@brandoncc Do you mind posting how you got this to work? Running into the same issue here.