martpie / next-transpile-modules

Next.js plugin to transpile code from node_modules. Please see: https://github.com/martpie/next-transpile-modules/issues/291
MIT License
1.13k stars 85 forks source link

Add option to disable Babel loader for certain packages #225

Closed fabianishere closed 1 year ago

fabianishere commented 3 years ago

I am developing a Next.js project in conjunction with the PatternFly 4. PatternFly's React components use global CSS imports internally, so I need this package to force Next.js to transpile the components into valid JavaScript.

As the project is growing, the compilation of the project is taking longer and longer. Obviously, some of this is expected due to needing to transpile the additional files. However, although I use this package only for the global CSS import functionality, as a result of using this package, all transpiled files will also have to go through the Babel loader.

In the case of PatternFly, this additional transpilation step is not necessary for it to work, so ideally I would like to be able to disable Babel for these packages. I have tested disabling the Babel loader locally and for my project it seems to halve the build times.

Proposal Allow users to disable Babel transpilation per package. I had something like this in mind:

// next.config.js
const withTM = require('next-transpile-modules')([
    'somemodule',  // Old behaviour, transpiled with Babel
    { name: 'and-another', babel: false }
]);

module.exports = withTM();
martpie commented 3 years ago

Did you have a look at the __unstable_matcher option?

fabianishere commented 3 years ago

@martpie I don't think that is sufficient enough to implement this functionality, given that the matcher is also used to enable global CSS imports and does not distinguish between the two use-cases: https://github.com/martpie/next-transpile-modules/blob/91b2413ae3ed6d3482a474f4eab97b6c4d8f449e/src/next-transpile-modules.js#L321