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.

Help upgrading to 1.x

See original GitHub issue

Hi and thanks for this great Rollup plugin. It’s been working well for me.

I am looking to upgrade from version 0.5.6 to 1.2.7 but am having difficulty figuring out what changes I need to make.

My use case is a React app with CSS modules. The existing setup is below:

const cssExportMap = {};

postcss({
    plugins : [
        cssModules({
            getJSON(id, exportTokens) {
                cssExportMap[id] = camelcaseKeys(exportTokens);
            },
            // Rc-slider needs some global CSS classes defined
            globalModulePaths : [/node_modules\/rc-slider\/assets\/index.css/]
        })
    ],
    getExportNamed : true,
    getExport(id) {
        return cssExportMap[id];
    }
})

The main goal of this special config is to enabled named imports with the more idiomatic convention of camelcase names, avoiding the -- to $__$ conversion that this plugin does by default.

/* sheet.css */
.foo-bar { background : blue }
import { fooBar } from './sheet.css';

… much better than …

import { foo$__$bar } from './sheet.css';

This worked perfectly prior to 1.0.0. Now I see output like below.

lib/js/components/nav-bar/nav-bar.jsx
navSearchWrapper is not exported by lib/css/nav-bar.css
21:             React.createElement(
22:                 'div',
23:                 { className: style.navSearchWrapper },
                                       ^
24:                 React.createElement('input', { name: 'search', id: 'nav-search', placeholder: 'Search' }),
25:                 React.createElement(Icon, { svgInfo: searchIcon, width: '25', height: '25' })

Based on what I see in the README now, I tried using the modules option, as below.

postcss({
    modules : {
        getJSON(id, exportTokens) {
            cssExportMap[id] = camelcaseKeys(exportTokens);
        },
        // Rc-slider needs some global CSS classes defined
        globalModulePaths : [/node_modules\/rc-slider\/assets\/index.css/]
    },
    getExportNamed : true,
    getExport(id) {
        return cssExportMap[id];
    }
})

But there was no effect, the output remains the same. Based on some logging I tried, it seems that getExport() is no longer being called.

I’m happy to migrate to any other pattern that achieves the same end goal of importing classes as camelcased names. Any advice on how to upgrade would be much appreciated.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
egoistcommented, Jan 30, 2018

Maybe simply camelcase the name and prefix with _ underscore if the final name is a reserved es keyword

1reaction
egoistcommented, Jan 30, 2018

seems we can really simplify this too:

https://github.com/egoist/rollup-plugin-postcss/blob/1820cf59a31d8648bec4dd73df32e47a0302e44a/src/postcss-loader.js#L29-L41

it just feels weird to import class-name as class$_$name 😅

/ping @lmihaidaniel what do you think?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to convert your bike to a 1x drivetrain - BikeRadar
How to convert your bike to a 1x drivetrain. Ditch the shifty bits. Remove your front shifter, front derailleur and all your geared...
Read more >
Upgrading A Kids Mountain Bike To A 1x Drivetrain
Before we started, our friend Steve from Hyland Cyclery took a look at the bike to help us identify all the tools and...
Read more >
Upgrading from 1.x — Fabric documentation - Fabfile.org
We recommend trying to write tests early on; they will help clarify the upgrade process for you & also make the process safer!...
Read more >
[How To] Build A Mountain Bike 1X Drivetrain Made Easy
The chain is also shorter and has more tension in a 1X drivetrain, which also helps on noise with riding over rough terrain....
Read more >
Need Help.. what the best way to upgrade this 3x to 1x? : r/MTB
Hi, I have this SC Blur that is pretty old but I love the way this bike handles. I would love to upgrade...
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