Socket
Socket
Sign inDemoInstall

postcss-load-config

Package Overview
Dependencies
3
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    postcss-load-config

Autoload Config for PostCSS


Version published
Weekly downloads
11M
decreased by-20.78%
Maintainers
1
Created
Weekly downloads
 

Package description

What is postcss-load-config?

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.

What are postcss-load-config's main functionalities?

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);
});

Other packages similar to postcss-load-config

Readme

Source

NPM Deps Tests Coverage Standard Code Style

Load Config

Autoload Config for PostCSS

Install

npm i -D postcss-load-config

Usage

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.

  • Create postcss section in your projects package.json.
  • Create a postcss.config.js or postcssrc.json file.

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.

Ordering

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)
]

Examples

package.json
{
 "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"
        }
      }  
    }
  }
}
postcss.config.js
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'
      }
    }
  }
}
postcssrc.json
{
  "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"
      }
    }
  }
}

Usage

Default
'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))
}))
Custom
'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

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.

Keywords

FAQs

Last updated on 07 Jul 2016

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc