nandorojo / solito

🧍‍♂️ React Native + Next.js, unified.
https://solito.dev
MIT License
3.54k stars 181 forks source link

Got NativeWind/tailwind working with babel plugins #317

Closed Gregoirevda closed 1 year ago

Gregoirevda commented 1 year ago

There's no need for the extra styled wrapper work (const View = styled(NativeView))

You can have the babel plugin working on expo I think without any additions besides Nativewind expo/bare RN setup. For it to work on NextJS, changing the next.config.js to

const nextConfig = {
//...

webpack: config => {
  config.module.rules.push({
      test: /\.(ts|tsx)$/,
      exclude: /node_modules/,
      use: {
        loader: 'babel-loader',
        options: {
          configFile: path.resolve(__dirname, '.babelrc'),
          babelrcRoots: ['../*'],
        },
      },
    });
  return config;
  }
}

requires yarn add -D babel-loader

This will apply your .babelrc on next directory and imports from ../packages

nandorojo commented 1 year ago

Thanks for sharing.

It's generally a good practice to wrap UI elements anyway in your own design system. That way, you can always intercept your own logic.

Also, in order to keep plugins optional and maintain support with SWC (recommended by Next.js), I'll retain the current suggestion.