rollup-plugin-postcss icon indicating copy to clipboard operation
rollup-plugin-postcss copied to clipboard

Impossible to inject CSS from a node_modules import

Open gablabelle opened this issue 4 years ago • 7 comments
trafficstars

So here is my rollup config

// tsdx.config.js
const postcss = require('rollup-plugin-postcss');
const autoprefixer = require('autoprefixer');
const cssnano = require('cssnano');
const tailwindcss = require('tailwindcss');

module.exports = {
  rollup(config, _options) {
    config.plugins.push(
      postcss({
        plugins: [
          autoprefixer(),
          tailwindcss(),
          cssnano({
            preset: 'default',
          }),
        ],
        extensions: ['.css'],
        modules: {
          scopeBehaviour: 'global',
          globalModulePaths: [
            /react-toastify/,
          ],
        },
        inject: true,
        extract: false,
      }),
    );
    return config;
  },
};

So if I import css file local from a relative path, it gets injected but I import from node_modules it doesn't

import React from 'react';
import { toast } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
// The following works if I copy the file locally
// import './ReactToastify.css';

What am I doing wrong here?

gablabelle avatar Jun 03 '21 19:06 gablabelle

same issue,did you solve it

wangJacker avatar Jun 08 '21 10:06 wangJacker

same issue,did you solve it

Nope.

gablabelle avatar Jun 08 '21 13:06 gablabelle

@gablabelle Hope you have found a solution for that. Is it fixed?

mjangir avatar Jul 29 '21 11:07 mjangir

@gablabelle Hope you have found a solution for that. Is it fixed?

Nope, we moved away from rollup in our monorepo for various reasons.

gablabelle avatar Jul 29 '21 17:07 gablabelle

I solved this issue by using peerDepsExternal({ includeDependencies: true }), but I am having issues with local css file.It is not injecting

CodeguruEdison avatar Sep 29 '21 19:09 CodeguruEdison

I find the sideEffects of [email protected] is :

  "sideEffects": [
    "*.css"
  ]

And ths css file is react-toastify/dist/ReactToastify.css ,so it will be tree-shaking.

2heal1 avatar Mar 23 '22 13:03 2heal1

In my case the issue with the @import was solved by removing the extension.

Instead of: @import 'react-toastify/dist/ReactToastify.css'

Use this: @import 'react-toastify/dist/ReactToastify'

antmihlin avatar Jan 26 '23 13:01 antmihlin