
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
Author collocated styles in JS, pull them during build time to ship static CSS. No runtime dependenc
Author collocated styles in JS, pull them during build time to ship static CSS. No runtime dependency.
I like to author styles collocated with component code, that's how I find them maintainable.
But before shipping them to users, I'd like to pull styles out of components and ship them in static CSS files. No runtime dependency.
prior art: This idea is not entirely new, there have been other similar interpretations of this idea before like callstack/linaria and atlassian-labs/compiled
input
App.js
import { css } from 'css-out-js';
const Title = (props) => {
return <h1 className={css({ fontSize: '2em' })}>Hello!</h1>;
};
output
The plugin extracts the styles into a css file
and replaces the function call with generated className string.
If there are any dynamic styles, it creates a css variable for them.
Finally, it removes the removes the import for css-out-js, no runtime.
dist.css
+.Title-1bdbzov {
+ font-size: 2em;
+}
App.js
- import { css } from 'css-out-js';
const Title = (props) => {
- return <h1 className={css({ fontSize: '2em' })}>Hello!</h1>;
+ return <h1 className="Title-1bdbzov">Hello!</h1>;
};
works with dynamic styles as well:
input
App.js
import { css } from 'css-out-js';
const Home = (props) => {
const className = css({ color: props.color });
return (
<section className={className}>
<p>Home sweet home</p>
</section>
);
};
output
Dynamic styles based on props are made possible by setting a css variable.
dist.css
+.Home-2b9glr {
+ color: var(--props-color-1trdzir);
+}
App.js
- import { css } from 'css-out-js';
const Home = (props) => {
- const className = css({ color: props.color });
+ const className = "Home-2b9glr"
+ document.documentElement.style.setProperty('--props-color-1trdzir', props.color),
return (
<section className={className}>
<p>Home sweet home</p>
</section>
);
}
install
npm install css-out-js --save-dev
# or
yarn add css-out-js --dev
Add plugin to babelrc, you can specify the location of your generated css file (hint: see examples directory)
module.exports = {
plugins: [['css-out-js/babel', { path: 'public/dist.css' }]]
};
add css import
this may differ based on the framework of your choice. (hint: see examples directory)
// App.js
import './dist.css';
FAQs
Author collocated styles in JS, pull them during build time to ship static CSS. No runtime dependenc
We found that css-out-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.