question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Module Federation with Tailwind

See original GitHub issue

Current Behavior

Running dep-graph in the project where modules are imported via module federation, federated modules are not marked as a dependency. This might be a problem because the Tailwind config file benefits from createGlobPatternsForDependencies and therefore federated modules need to be added with a custom glob pattern.

Expected Behavior

createGlobPatternsForDependencies should work with federated modules. I just expect that one tailwind config should be enough.

Steps to Reproduce

Just create a module federation demo with nx and add tailwind to your host application. Try to use tailwind in federated modules or its child libraries.

Failure Logs

image

Environment

Nearly the same repo --> https://github.com/Coly010/example-nx-ng-mfe Angular based mfe’s.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
bressanellecommented, Jun 16, 2022

hey @sdedieu. I guess I found a way to workaround this situation without using apply in each component.

I created tailwind.config.js in root level of monorepo like that

const { createGlobPatternsForDependencies } = require('@nrwl/angular/tailwind');
const { join } = require('path');

module.exports = {
  darkMode: 'class',
  content: [
    join(__dirname, 'apps/frontend/*/src/**/!(*.stories|*.spec).{ts,html}'),
    ...createGlobPatternsForDependencies(__dirname),
  ],
  theme: {
    extend: {},
  },
  plugins: [require('@tailwindcss/forms')],
};

then I removed of my shell and remote apps all styles using

@tailwind base;
@tailwind components;
@tailwind utilities;

and I also removed their own tailwind.config.js

So I created a lib called ui/common with globalTailwind.css that uses tailwind config

@tailwind base;
@tailwind components;
@tailwind utilities;

and finally added in shell and remote apps in their project.json "styles": ["libs/ui/common/styles/globalTailwind.css"],

I dont know if it is a elegant method to solve this problem but now my remotes apps and shell are using tailwind utilities classes in their html files. Dark theme also works

1reaction
Coly010commented, Jun 20, 2022

@bressanelle It should work, but the downside is you lose the benefit of the Tailwind’s PostCSS Purge step where it reduces the size of your CSS bundle.

But it is a workaround.

I’m going to close this issue as this is a limitation of the tooling, and there is a workaround listed above.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tailwind CSS + Module Federation - ng-journal
Tailwind CSS is a modern CSS utility library used by thousands of people. It allows to use predefined css classes directly inside the...
Read more >
Building Micro Frontend with React & Module Federation
We will be creating a production-ready micro-front end app using React, Redux, Typescript, Tailwind CSS, React Router, and Webpack but the ...
Read more >
r/javascript - Tailwind CSS + Module Federation [Angular]
The thing is Angular is a complete fremework. With bare React you can't create anything serious.
Read more >
Tailwind CSS Gems, Micro-Frontends, 3 Biggest Failures
Micro-Frontends: What, why, and how. Micro-Frontend is super buzzed right now thanks to Webpack 5 and Module Federation. Learn how to use it ......
Read more >
Module Federation - SurviveJS
To get started with module federation, let's build a small application that ... The styling portion uses Tailwind setup from the Eliminating Unused...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found