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

Tailwind CSS is not included in consumer package only for production build. #212

Closed fawwaz closed 3 years ago

fawwaz commented 3 years ago

Are you trying to transpile a local package or an npm package? If an npm package, which one? Local Package

Describe the bug A clear and concise description of what the bug is (don't forget the logs if applicable). I created a monorepo setup using lerna. I plan to have 2 packages:

.
└── packages
    ├── web-app (consumer)
    └── web-ui (using tailwind)
When I run web-app for development mode, (yarn dev) the tailwind styling is applied (the component that is located within web-ui is styled correctly). However, when I run for production build (yarn build) the tailwind styling is missing (I guess it is purged (?)) yarn dev yarn build
Screenshot from 2021-05-27 11-10-06 Screenshot from 2021-05-27 11-08-52

To Reproduce Steps to reproduce the behavior (a reproduction is even better):

  1. Clone this repository : https://github.com/fawwaz/next-transpile-modules-issue
  2. Run yarn install in the root folder
  3. Run yarn build in packages/web-app
  4. Run yarn start in packages/web-app

Expected behavior A clear and concise description of what you expected to happen.

Running production build should include the tailwind styling.

Setup

Additional context Add any other context about the problem here.

martpie commented 3 years ago

Have you tried disabling purge completely to see if it would make it work? Because it looks more like an issue in your setup than an issue with ntm.

fawwaz commented 3 years ago

I tried. Yes, removing purge option loads the entire CSS, but it also means the objective of purge CSS is not achieved as it also loads any irrelevant CSS rules.

I think I should rephrase the question : how can I set the webpack option(purge CSS option) so it will purge the CSS from local module ?

martpie commented 3 years ago

Well then it's not exactly related to next-transpile-modules, it's really just about applying purge to your packages in node_modules.

If I had to look somewhere, I'd check your tailwind config and add a glob there:

https://github.com/fawwaz/next-transpile-modules-issue/blob/master/packages/web-app/tailwind.config.js

purge: [
  "./pages/**/*.{js.ts,tsx,jsx}",
  "./components/**/*.{js.ts,tsx,jsx}",
  "web-ui/**/*.{js.ts,tsx,jsx}"
]

No idea if it will work, but you can play with require.resolve to get the path to your package as well, but it's definitely where it should be fixed.