
Security News
New CVE Forecasting Tool Predicts 47,000 Disclosures in 2025
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
postcss-node
Advanced tools
Package which allows import of css/scss/lass/.. files under the node.js eg `require('styles.css')`
Package which allows import of css files under the node.js eg require('styles.css')
This package should be used together with postcss-es-modules
By using require.extensions
this package register the handlers which on the fly, on runtime,
for each .css
file require is transpiling the css content by using postcss.
To be able to load the .css
file as javascript module, you should use
postcss-es-modules post css plugin.
npm i postcss-node postcss-es-modules
Firstly we need to provide the proper postcss configuration, you can add it to your package.json, or keep it in separate file eg:
/* postcss.config.js */
module.exports = {
"plugins": {
// this plugin will transform css into the js module
"postcss-es-modules": {
"inject": {
// we will use the common js modules
"moduleType": "cjs"
}
}
}
}
You can register the .css/.sass
files handle just by the -r
node.js option.
node -r postcss-node/register test.js
/* test.js */
const { styles, css } = require('./test.css');
console.log(css);
console.log(styles.a);
/* test.css */
.a {
color: blue;
}
Or you can register the handle manually within the code.
node test.js
/* test.js */
const { register } = require('postcss-node');
register();
const { styles, css } = require('./test.css');
console.log(css);
console.log(styles.a);
/* test.css */
.a {
color: blue;
}
The register
function is able to take the optional parameter, which will be the array of the
file extensions which should be handled by that package. By default, register
is
attaching handlers for the '.css', '.scss', '.sass', '.less', '.stylus'.
node test.js
/* test.js */
const { register } = require('postcss-node');
register(['.acss', '.bcss', '.css']);
const { styles, css } = require('./test.acss');
console.log(css);
console.log(styles.a);
/* test.acss */
.a {
color: blue;
}
You can also provide the custom extensions by the
POSTCSS_NODE_EXT
environment variable like:cross-env POSTCSS_NODE_EXT=.acss,.bcss,.css
The register
function is able to take the two more optional parameter
POSTCSS_NODE_TIMEOUT
) - the timeout of css processing, default 60000 msPOSTCSS_NODE_BUFFER_SIZE
) - the size of buffer used to transfer compiled code from
the worker, in case of RangeError [ERR_BUFFER_OUT_OF_BOUNDS]: "length" is outside of buffer bounds
error please increase this parameter, default 1024 kBIf you have any problems, issues, ect. please use github discussions.
FAQs
Package which allows import of css/scss/lass/.. files under the node.js eg `require('styles.css')`
The npm package postcss-node receives a total of 3,483 weekly downloads. As such, postcss-node popularity was classified as popular.
We found that postcss-node 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
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.