
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
postcss-load-config
Advanced tools
The postcss-load-config package is used to load PostCSS configurations automatically. It helps in finding and loading a PostCSS configuration file, which can be in different formats like .postcssrc, postcss.config.js, or directly in package.json. It simplifies the process of setting up PostCSS by abstracting the configuration loading logic.
Loading PostCSS Configurations
This feature allows you to load the PostCSS configuration from a file or package.json. The code sample demonstrates how to use the package to load the configuration and then use it to process CSS with PostCSS.
const postcssLoadConfig = require('postcss-load-config');
postcssLoadConfig().then(({ plugins, options }) => {
// Use the loaded plugins and options to process your CSS with PostCSS
postcss(plugins).process(yourCss, options);
}).catch((error) => {
console.error('Failed to load PostCSS config:', error);
});
Cosmiconfig is a package that searches for and loads configuration for your program. It supports several file formats and locations for the configurations. It is similar to postcss-load-config but is more generic and not limited to PostCSS configurations.
webpack-config-loader is a package that helps load and customize webpack configurations. It is similar to postcss-load-config in that it abstracts the configuration loading process, but it is specific to webpack rather than PostCSS.
require-from-string allows you to require modules from a string of code. It is similar to postcss-load-config in that it can be used to load configurations dynamically, but it does not have the built-in logic to search for configuration files.
npm i -D postcss-load-config
Install plugin as usual and make sure saving them to your package.json dependencies and/or devDependencies.
npm i -S postcss-plugin
npm i -D postcss-plugin
After installing your plugins there a two common ways to declare your plugins and options.
Plugin options can either take null
or an object literal {}
as value.
null
: Plugin loads with no options (defaults).
[Object]
: Plugin loads with set options.
Plugin order is determined by declaration in the plugins section.
postcss: {
parser: require('sugarss'),
from: 'app.sss'
map: 'inline',
to: 'app.css'
plugins: {
'postcss-plugin1': null,
'postcss-plugin2': null,
'postcss-plugin3': {option1: '', option2: ''}
}
}
// Loaded Options Setup
{
parser: require('sugarss'),
from: 'app.sss'
map: 'inline',
to: 'app.css'
}
// Loaded Plugin Setup
[
require('postcss-plugin1')(),
require('postcss-plugin2')(),
require('postcss-plugin3')(options)
]
{
"dependencies": {
"sugarss": "^0.1.4",
"postcss-bem": "^0.2.2",
"postcss-nested": "^1.0.0",
"postcss-import": "^8.1.2"
},
"postcss": {
"parser": "sugarss",
"from": "app.sss",
"map": "inline",
"to": "app.css",
"plugins": {
"postcss-import": null,
"postcss-nested": null,
"postcss-bem": {
"style": "bem",
"separators": {
"namespace": "-",
"descendent":"__",
"modifier": "--"
},
"shortcuts": {
"component": "block",
"descendent": "elem",
"modifier": "mods"
}
}
}
}
}
module.exports = {
parser: "sugarss",
from: 'app.sss',
map: 'inline',
to: 'app.css',
plugins: {
'postcss-import': null,
'postcss-nested': null,
'postcss-bem': {
style: 'bem',
separators: {
namespace: '-',
descendent: '__',
modifier: '--'
},
shortcuts: {
component: 'block',
descendent: 'elem',
modifier: 'mods'
}
}
}
}
{
"parser": "sugarss",
"from": "app.sss",
"map": "inline",
"to": "app.css",
"plugins": {
"postcss-import": null,
"postcss-nested": null,
"postcss-bem": {
"style": "bem",
"separators": {
"namespace": "-",
"descendent":"__",
"modifier": "--"
},
"shortcuts": {
"component": "block",
"descendent": "elem",
"modifier": "mods"
}
}
}
}
'use strict'
const { readFileSync } = require('fs')
const postcss = require('postcss')
const postcssrc = require('postcss-load-config')()
const css = readFileSync('./index.css', 'utf8')
postcssrc.then(({ plugins, options }) => {
postcss(plugins)
.process(css, options)
.then(result => console.log(result.css))
}))
'use strict'
const { readFileSync } = require('fs')
const postcss = require('postcss')
const postcssrc = require('postcss-load-config')('./path/to/postcssrc.json')
const css = readFileSync('./index.css', 'utf8')
postcssrc.then(({ plugins, options }) => {
postcss(plugins)
.process(css, options)
.then(result => console.log(result.css))
}))
License (MIT)
Copyright (c) 2016 Michael Ciniawsky
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Autoload Config for PostCSS
The npm package postcss-load-config receives a total of 14,319,973 weekly downloads. As such, postcss-load-config popularity was classified as popular.
We found that postcss-load-config demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers 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
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.