Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output contains const keyword for stylesheet export #282

Closed
jessethomson opened this issue May 29, 2020 · 1 comment · Fixed by #283
Closed

Output contains const keyword for stylesheet export #282

jessethomson opened this issue May 29, 2020 · 1 comment · Fixed by #283

Comments

@jessethomson
Copy link
Contributor

Problem

The output generated when using the stylesheet export contains the const keyword, causing the code to break in some areas.

Solution

Replace const with var on the following line:

`export const stylesheet=${JSON.stringify(result.css)};`

Use Case

I have a library that contains all the styles for multiple component libraries. The component libraries have different ways of injecting the styles so I use the inject: false option of rollup-plugin-postcss, and let each library handle injection. In the styles library, I need to be able to export both the 1) js object of classNames, and 2) the raw css content so that the component libraries can use it.

The best way I have found to achieve that is this:

export { default as ButtonStyles, stylesheet as ButtonCSS } from './button.css'

As such, I need the stylesheet export because when using css modules, the default export is just the js object.

(Happy to go into more details on my use case, basically just trying to say enough to make it clear that I need the actual stylesheet export.)

Steps to Repro

Config:

rollup.config.js

import postcss from 'rollup-plugin-postcss';

export default {
    input: 'src/index.js',
    output: {
        file: 'dist/index.js',
        format: 'es',
    },
    plugins: [
        postcss({ inject: false }),
    ]
}

Input:

src/index.js

export { stylesheet } from './index.css';

src/index.css

.test {
  color: blue;
}

Output:

dist/index.js

const stylesheet=".test {\n    color: blue;\n}";

console.log(stylesheet);
@jessethomson
Copy link
Contributor Author

Is there a rough estimate for when I could expect this change to be released? No pressure, just curious.

Thanks for all you do on this project!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant