
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
postcss-js-syntax
Advanced tools
For use powerful JavaScript syntax for compile CSS instead legacy preprocessors: SASS, LESS, Stylus, etc.
It turned out that no one CSS preprocessor is able to provide modularity of styles at the development level.
The convenience of preprocessors in the details is completely leveled when the application grows, because the preprocessors cannot provide adequate modularity.
When I have such a powerful tool at hand as JavaScript - it would not be wise not to use it.
Styles written in JavaScript are not so convenient, but when extending even a small project, the power of the JavaScript language fully compensated for this drawback.
Converter between Postcss-Js-Syntax and CSS
You can use your JS modules for compile CSS files.
CSS styles in JavaScript format represent an simple object:
my-style.js
module.exports = [
"@at-rule-wiwhout-params", // starts with @
"@at-rule with params",
"@at-rule (with params)",
"// comment", // starts with "//" or "/*"
{
".selector1": {
color: "#0f0"
},
".selector2": {
color: "#0f0"
}
},
"// another comment",
{
"@at-rule (with params)": {
"and-content": "value"
},
".selector3": {
color: "#0f0",
".sub-selector": { // you can use postcss-nested plugin here
content: '"quotes is required for this CSS property"'
}
}
}
]
One possible use case:
import postcss from 'postcss'
import jsSyntax from 'postcss-js-syntax'
const css = postcss([...your plugins])
.process(
'', // this parameter will be ignored by js parser
{
from: require.resolve('./myJsStyle.js'), // required absolute path to real file
parser: jsSyntax.parser,
requireFromString: function(code, filename) {
// you can provide your own requireFromString function
// default:
return require(filename)
}
}
console.log(css)
I recommend to use require-from-memory npm module in requireFromString option, because it allows you to use ES6 modules with babel like this:
import myModule './my-module.js'
import myNodeModule 'my-node-module'
export default [
...myModule.baseStyles({fontSize: "5px"}), // mixin equivalent
{
...myNodeModule?.myCssClasses, // see @babel/plugin-proposal-optional-chaining
.override-selector {
color: myNodeModule?.colors?.primary, // if color == null it will not be added to CSS
content: myNodeModule.myContent?.surroundWithQuotes()
}
}
]
FAQs
For use powerful JavaScript syntax for compile CSS instead legacy preprocessors: SASS, LESS, Stylus, etc.
We found that postcss-js-syntax 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
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.