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

Use next.js method for detecting webpack 5 #110

Closed ScriptedAlchemy closed 4 years ago

ScriptedAlchemy commented 4 years ago

I noticed you opted towards unstable_webpack5 flag that's manually passed.

Just wanted some information on why we need a manual flag for this, the rest of next and patched community plugins / loaders use the require('webpack').version to determine if its WP5 automatically

martpie commented 4 years ago

require('webpack').version requires Webpack at runtime, and Webpack in not installed at production time with npm install --production and yarn install --production, as it is a dev dependencies.

So this is why you need to pass a flag, because require('webpack') would throw at runtime on production.

martpie commented 4 years ago

sidenote: It works for Next.js because they only use it at build time, and not at runtime (and next.config.js is executed also at runtime)

ScriptedAlchemy commented 4 years ago

Thanks! Was wondering 💭