Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
babel-plugin-css-to-module
Advanced tools
Readme
babel-plugin-css-to-module
A babel plugin that transforms css into css-modules using tagged template literals. The output is a raw string of data which is parsed using either the react hook use-inline-css-modules or any other custom template literal tag.
This plugin is framework-agnostic, but we'll be using React in most of the examples.
With css modules, you would write css in its own file and import it into your component:
/* my-styles.css */
.someStyle {
background-color: red;
}
// my-compoennt.jsx
import styles from "./my-styles.css";
function MyComponent() {
return <div className={styles.someStyle}>Hello, world!</div>;
}
babel-plugin-css-to-module
allows you to write your css as a string inline:
function MyComponent() {
return <div className={styles.someStyle}>Hello, world!</div>;
}
const { styles } = cssModules`
.someStyle {
background-color: red;
}
`;
This plugin will target the cssModules
tag (or any other name you want), and
transform the string into parsable raw data.
This plugin uses postcss, and requires it as a peer dependency.
yarn add -D postcss babel-plugin-css-to-module
# or
npm add -D postcss babel-plugin-css-to-module
Add plugin to your babel config
{
"plugins": [
["babel-plugin-css-to-module", {
// options here
}]
]
}
tagName
string
This plugin works by targeting and transforming specifically named template
literal tags. By default, all template literals named cssModules
will be
processed. This can be overridden using the tagName
option.
{
"plugins": [
["babel-plugin-css-to-module", {
"tagName": "customName"
}]
]
}
const { styles } = customName`
.test {
background-color: red;
}
`;
postcssPlugins
postcssPlugins
is a passthrough option for postcss plugins. The order of
plugins will be:
[...passedInPlugins, cssModulePlugin()]
.
sassOptions
{ additionalData: string; ...restOfSassOptions }
Because I'm partial to Sass 😉, I've added the ability to run your css through
the Sass engine before being transformed. To enable this, install
sass and add sassOptions
to
your babel config (object):
{
"plugins": [
["babel-plugin-css-to-module", {
"sassOptions": {}
}]
]
}
The additionalData
sass option will prepend any sass to the
beginning of your stylesheets (think variables and mixins).
The rest of the properties are pass-through options for sass, and can be found in their docs: sass javascript api.
Note: even if you don't need sass options, you still must pass an object for the sass compiler to run.
FAQs
[![npm version](https://badge.fury.io/js/babel-plugin-css-to-module.svg)](https://badge.fury.io/js/babel-plugin-css-to-module)
We found that babel-plugin-css-to-module demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.