gajus / babel-plugin-react-css-modules

Transforms styleName to className using compile time CSS module resolution.
Other
2.05k stars 162 forks source link

Feature Request: Add an option to specify the module path of getClassName #172

Closed otakustay closed 6 years ago

otakustay commented 6 years ago

Currently babel-plugin-react-css-modules requires to be installed as runtime dependency since it generates an import to babel-plugin-react-css-modules/dist/browser/getClassName

In our case, we use a private package to encapsulate all babel plugins, we don't want our users to be aware to the babel-plugin-react-css-modules, neither do we want them to install it themselves

We think a solution could be this plugin providing an option runtimeModulePath to identify this runtime helper module, for example when our private package is our-fe-tools, we config it as:

[
  require.resolve('react-css-modules'),
  {
    runtimeModulePath: 'our-fe-tools/lib/styleNameHelper'
  }
]

Then import statement is transformed to import getClassName from 'our-fe-tools/lib/styleNameHelper' so we can entirely encapsulate all babel plugins

gajus commented 6 years ago

This seems entirely esoteric issue with no practical applications.

jpsear commented 5 years ago

This would be a great feature. @gajus For a use-case, think of create-react-app, where all the webpack and build configuration is abstracted away from the consumer...

@otakustay Did you find a way around this? What you explained is exactly what we are trying to do too...