All Projects → egoist → Rollup Plugin Postcss

egoist / Rollup Plugin Postcss

Licence: mit
Seamless integration between Rollup and PostCSS.

Programming Languages

javascript
184084 projects - #8 most used programming language
stylus
462 projects

Projects that are alternatives of or similar to Rollup Plugin Postcss

Rollup Plugin Styles
🎨 Universal Rollup plugin for styles: PostCSS, Sass, Less, Stylus and more.
Stars: ✭ 116 (-77.12%)
Mutual labels:  rollup, sass, less, postcss, css-modules
React Native Css Modules
Style React Native components using CSS, PostCSS, Sass, Less or Stylus.
Stars: ✭ 207 (-59.17%)
Mutual labels:  sass, less, postcss, css-modules
Cessie
Transpile your CSS bundle to support CSS variables, calc, and future CSS for legacy browsers.
Stars: ✭ 81 (-84.02%)
Mutual labels:  sass, less, postcss
Static Site Boilerplate
A better workflow for building modern static websites.
Stars: ✭ 1,633 (+222.09%)
Mutual labels:  sass, less, postcss
Webpack Encore
A simple but powerful API for processing & compiling assets built around Webpack
Stars: ✭ 1,975 (+289.55%)
Mutual labels:  sass, less, postcss
Stylelint
A mighty, modern linter that helps you avoid errors and enforce conventions in your styles.
Stars: ✭ 9,350 (+1744.18%)
Mutual labels:  sass, less, postcss
webpack-typescript-react
Webpack 5 boilerplate with support of most common loaders and modules (see tags and description)
Stars: ✭ 185 (-63.51%)
Mutual labels:  less, postcss, css-modules
Vscode Stylelint
A Visual Studio Code extension to lint CSS/SCSS/Less with stylelint
Stars: ✭ 260 (-48.72%)
Mutual labels:  sass, less, postcss
Moo Css
模块化面向对象的css写法规范策略。适用于大中小型C端项目样式开发,旨在提高开发和维护效率。
Stars: ✭ 79 (-84.42%)
Mutual labels:  sass, less, css-modules
Prejss
Get the power of PostCSS with plugins in your JSS styles. 🎨 Just put CSS into JS and get it as JSS object.
Stars: ✭ 238 (-53.06%)
Mutual labels:  sass, less, postcss
Kit
ReactQL starter kit (use the CLI)
Stars: ✭ 232 (-54.24%)
Mutual labels:  sass, less, postcss
Kratos Boilerplate
🔥 A simple boilerplate for creating statics PWA using Webpack, Pug, PostCSS and CSS Modules
Stars: ✭ 308 (-39.25%)
Mutual labels:  sass, postcss, css-modules
Reactql
Universal React+GraphQL starter kit: React 16, Apollo 2, MobX, Emotion, Webpack 4, GraphQL Code Generator, React Router 4, PostCSS, SSR
Stars: ✭ 1,833 (+261.54%)
Mutual labels:  sass, less, postcss
Reset Css
An unmodified* copy of Eric Meyer's CSS reset. PostCSS, webpack, Sass, and Less friendly.
Stars: ✭ 244 (-51.87%)
Mutual labels:  sass, less, postcss
Modular Css
A streamlined reinterpretation of CSS Modules via CLI, API, Browserify, Rollup, Webpack, or PostCSS
Stars: ✭ 234 (-53.85%)
Mutual labels:  rollup, postcss, css-modules
next-plugin-antd-less
🎩 Use Antd (Less) with Next.js v12, Zero Dependency on other Next-Plugins.
Stars: ✭ 338 (-33.33%)
Mutual labels:  less, css-modules
criteria-of-quality-frontend
Критерии качественной вёрстки (разметка, стилизация, картинки, шрифты, автоматизация и пр.)
Stars: ✭ 26 (-94.87%)
Mutual labels:  less, postcss
react.js
A boilerplate for react js project. 基于 reactjs+redux+webpack2 的单页应用项目模板。
Stars: ✭ 28 (-94.48%)
Mutual labels:  postcss, css-modules
prepublish
Simplifies the prepare step (bundling, transpiling, rebasing) during publishing NPM packages.
Stars: ✭ 21 (-95.86%)
Mutual labels:  postcss, rollup
dva-typescript-antd-starter-kit
A admin dashboard application demo based on antd by typescript and dva
Stars: ✭ 61 (-87.97%)
Mutual labels:  less, postcss

rollup-plugin-postcss

NPM version NPM downloads Build Status codecov donate

Seamless integration between Rollup and PostCSS.

Install

yarn add postcss rollup-plugin-postcss --dev

Usage

v2.0 support rollup v1 or above, but it prints deprecated warning from rollup v2.

Breaking change: v3.0 only support rollup v2, and the extract path based on bundle root the location of the generated file outside the bundle directory not allowed in rollup v2.

// rollup.config.js
import postcss from 'rollup-plugin-postcss'

export default {
  plugins: [
    postcss({
      plugins: []
    })
  ]
}

Then you can use CSS files:

import './style.css'

Note that the generated CSS will be injected to <head> by default, and the CSS string is also available as default export unless extract: true:

// Inject to `<head>` and also available as `style`
import style from './style.css'

It will also automatically use local PostCSS config files.

Extract CSS

// for v2
postcss({
  extract: true,
  // Or with custom file name, it will generate file relative to bundle.js in v3
  extract: 'dist/my-custom-file-name.css'
})

// for v3
import path from 'path'
postcss({
  extract: true,
  // Or with custom file name
  extract: path.resolve('dist/my-custom-file-name.css')
})

CSS modules

postcss({
  modules: true,
  // Or with custom options for `postcss-modules`
  modules: {}
})

With Sass/Stylus/Less

Install corresponding dependency:

  • For Sass install node-sass: yarn add node-sass --dev
  • For Stylus Install stylus: yarn add stylus --dev
  • For Less Install less: yarn add less --dev

That's it, you can now import .styl .scss .sass .less files in your library.

imports

For Sass/Scss Only.

Similar to how webpack's sass-loader works, you can prepend the path with ~ to tell this plugin to resolve in node_modules:

@import "~bootstrap/dist/css/bootstrap";

Options

extensions

Type: string[]
Default: ['.css', '.sss', '.pcss']

This plugin will process files ending with these extensions and the extensions supported by custom loaders.

plugins

Type: Array

PostCSS Plugins.

inject

Type: boolean object function(cssVariableName, fileId): string

Default: true

Inject CSS into <head>, it's always false when extract: true.

You can also use it as options for style-inject.

It can also be a function , returning a string which is js code.

extract

Type: boolean string
Default: false

Extract CSS to the same location where JS file is generated but with .css extension.

You can also set it to an absolute path.

modules

Type: boolean object
Default: false

Enable CSS modules or set options for postcss-modules.

autoModules

Type: boolean
Default: true

Automatically enable CSS modules for .module.css .module.sss .module.scss .module.sass .module.styl .module.stylus .module.less files.

namedExports

Type: boolean function
Default: false

Use named exports alongside default export.

You can supply a function to control how exported named is generated:

namedExports(name) {
  // Maybe you simply want to convert dash to underscore
  return name.replace(/-/g, '_')
}

If you set it to true, the following will happen when importing specific classNames:

  • dashed class names will be transformed by replacing all the dashes to $ sign wrapped underlines, eg. -- => $__$
  • js protected names used as your style class names, will be transformed by wrapping the names between $ signs, eg. switch => $switch$

All transformed names will be logged in your terminal like:

Exported "new" as "$new$" in test/fixtures/named-exports/style.css

The original will not be removed, it's still available on default export:

import style, { class$_$name, class$__$name, $switch$ } from './style.css'
console.log(style['class-name'] === class$_$name) // true
console.log(style['class--name'] === class$__$name) // true
console.log(style['switch'] === $switch$) // true

minimize

Type: boolean object
Default: false

Minimize CSS, boolean or options for cssnano.

sourceMap

Type: boolean "inline"

Enable sourceMap.

parser

Type: string function

PostCSS parser, like sugarss.

stringifier

Type: string function

PostCSS Stringifier.

syntax

Type: string function

PostCSS Syntax.

exec

Type: boolean

Enable PostCSS Parser support in CSS-in-JS.

config

Type: boolean object
Default: true

Load PostCSS config file.

config.path

Type: string

The path to config file, so that we can skip searching.

config.ctx

Type: object

ctx argument for PostCSS config file.

Note: Every key you pass to config.ctx will be available under options inside the postcss config.

// rollup.config.js
postcss({
  config: {
    ctx: {
      foo: 'bar'
    }
  }
})

// postcss.config.js
module.exports = context => {
  console.log(context.options.foo) // 'bar'

  return {}
}

to

Type: string

Destination CSS filename hint that could be used by PostCSS plugins, for example, to properly resolve path, rebase and copy assets.

use

Type: name[] [name, options][] { sass: options, stylus: options, less: options }

Default: ['sass', 'stylus', 'less']

Use a loader, currently built-in loaders are:

  • sass (Support .scss and .sass)
  • stylus (Support .styl and .stylus)
  • less (Support .less)

They are executed from right to left.

If you pass the object, then its property sass, stylus and less will be pass in the corresponding loader.

loaders

Type: Loader[]

An array of custom loaders, check out our sass-loader as example.

interface Loader {
  name: string,
  test: RegExp,
  process: (this: Context, input: Payload) => Promise<Payload> | Payload
}

interface Context {
  /** Loader options */
  options: any
  /** Sourcemap */
  sourceMap: any
  /** Resource path */
  id: string
  /** Files to watch */
  dependencies: Set<string>
  /** Emit a waring */
  warn: PluginContext.warn
  /** https://rollupjs.org/guide/en#plugin-context */
  plugin: PluginContext
}

interface Payload {
  /** File content */
  code: string
  /** Sourcemap */
  map?: string | SourceMap
}

onImport

Type: id => void

A function to be invoked when an import for CSS file is detected.

License

MIT © EGOIST

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].