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

Transpiling all code in package regardless of webpack config #277

Closed conor909 closed 1 year ago

conor909 commented 1 year ago

I have a shared UI library in my monorepo written in react native (web), and in my webpack config I have the blow code.

Webpack should ignore files such as index.tsx if index.web.tsx is a sibling file. But my case the transpiler is attempting to transpile native libraries imported into index.tsx when it shouldn't.

/** @type {import('next').NextConfig} */

const withFonts = require('next-fonts')
const withImages = require('next-images')
const withPlugins = require('next-compose-plugins')
const withTM = require('next-transpile-modules')([
  '@my/ui-library'
])

const nextConfig = {
  reactStrictMode: false,
  webpack5: true,
  swcMinify: true,
  webpack: (config) => {
    config.resolve.extensions = [
      '.web.ts',
      '.web.tsx',
      '.web.js',
      '.web.jsx',
      ...config.resolve.extensions,
    ]
    return config
  }
}

const transform = withPlugins([withTM, withFonts, withImages])

module.exports = function (name, { defaultConfig }) {
  return transform(name, {
    ...defaultConfig,
    ...nextConfig,
  })
}