egoist / egoist/rollup-plugin-postcss

styleInject breaks tree-shaking

Open
#293 12 comments 2 reactions 0 assignees View on GitHub
discuss
Dominant language
JavaScript
Stars
689
Forks
210
PR merge metrics
No merged PRs in 30d

Description

This function doesn't have a `/*#__PURE__*/` prefix, which breaks tree-shaking. Moreover, when I try to prepend it myself through `inject` option it gets stripped along with the entire string from the final bundle, which leaves you without CSS.

```js
function inject(cssVariableName) {
return (
'\n' +
`/*#__PURE__*/ (${styleInjectFork})(${cssVariableName}${
Object.keys(styleInjectOptions).length > 0
? `,${JSON.stringify(styleInjectOptions, function(_key, value) {
if (typeof value === 'function') {
return value.toString();
}
return value;
})}`
: ''
});`
);
}
```

In my case, I forked `styleInject`, because it's missing some features, so I had to compose it slightly different into the string (wrap it with brackets to turn it into expression, which is then invokable).

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.