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.

Extract CSS separately for every file of the array of rollup entry points

See original GitHub issue

Extracting CSS into a single file breaks treeshaking. I only want to ship critical styles. So as rollup turns every entry point to separate output chunks it would be great if there were a possibility to have the same for CSS instead of just generating one file which contains all the styles.

// config

rollupConfig = {
    input: ['./src/components/Button/index.js', './src/components/Input/index.js'],
    output: [
        {
            dir: lib,
            format: 'cjs',
            sourcemap: true,
            exports: 'named'
        },
    ],
    plugins: [
        postcss({
                modules: true,
                extract: true,
                sourceMap: true,
                minimize: true
            })
    ]
}

// result

.
└───components
│   └─── Input
│       │   index.js
│   └─── Button
│       │   index.js
└───folder2
│   index.js
│   chunk.js
│   styles.css

//expected result

.
└───components
│   └─── Input
│       │   index.js
│       │   styles.css
│   └─── Button
│       │   index.js
│       │   styles.css
└───folder2
│   index.js
│   chunk.js
│   styles.css

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:92
  • Comments:14

github_iconTop GitHub Comments

16reactions
frattarocommented, May 27, 2020

Here’s a use case:

You have a large react-rollup component library that is consumed by a create-react-app application. They only need one component, and also need to run postcss on that component’s css to ensure it’s properly scoped. The component library already ships each component as a separate entry point, but can’t get the per-component css extracted, and are unable to support postcss in the consuming application.

8reactions
3lang3commented, Mar 10, 2022

has any progress for this feature ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bundle Stylesheets and Add LiveReload With Rollup
Learn how to use the JavaScript bundler Rollup to process stylesheets using PostCSS and rebuild & reload files when changes are made in...
Read more >
Extract CSS separately for every file of the array of rollup entry points
Extracting CSS into a single file breaks treeshaking. I only want to ship critical styles. So as rollup turns every entry point to...
Read more >
rollup.js
You can export an array from your config file to build bundles from several unrelated inputs at once, even in watch mode. To...
Read more >
Create separate CSS files in postcss & rollup - Stack Overflow
js", }, plugins: [ resolve({ browser: true, }), postcss({ plugins: [postcssImport(), postcssNested(), autoprefixer()], extract: true, sourceMap: ...
Read more >
The Ultimate Guide to Getting Started with the Rollup.js ...
The tool compiles all your JavaScript source files into a single ... easy to get started but you'll discover plugins for HTML, CSS,...
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