All Projects → Anidetrix → Rollup Plugin Styles

Anidetrix / Rollup Plugin Styles

Licence: mit
🎨 Universal Rollup plugin for styles: PostCSS, Sass, Less, Stylus and more.

Programming Languages

typescript
32286 projects
stylus
462 projects

Projects that are alternatives of or similar to Rollup Plugin Styles

Rollup Plugin Postcss
Seamless integration between Rollup and PostCSS.
Stars: ✭ 507 (+337.07%)
Mutual labels:  rollup, sass, less, postcss, css-modules
Vscode Stylelint
A Visual Studio Code extension to lint CSS/SCSS/Less with stylelint
Stars: ✭ 260 (+124.14%)
Mutual labels:  scss, sass, less, postcss
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 (+105.17%)
Mutual labels:  scss, sass, less, postcss
Cessie
Transpile your CSS bundle to support CSS variables, calc, and future CSS for legacy browsers.
Stars: ✭ 81 (-30.17%)
Mutual labels:  scss, sass, less, postcss
Stylelint
A mighty, modern linter that helps you avoid errors and enforce conventions in your styles.
Stars: ✭ 9,350 (+7960.34%)
Mutual labels:  scss, sass, less, postcss
React Native Css Modules
Style React Native components using CSS, PostCSS, Sass, Less or Stylus.
Stars: ✭ 207 (+78.45%)
Mutual labels:  sass, less, postcss, css-modules
Vertical Rhythm
Put some typographical vertical rhythm in your CSS. LESS, Stylus and SCSS/SASS versions included.
Stars: ✭ 83 (-28.45%)
Mutual labels:  styles, scss, sass, less
Rfs
✩ Automates responsive resizing ✩
Stars: ✭ 2,789 (+2304.31%)
Mutual labels:  scss, sass, postcss
Webpack4.x
webpack4.x详细配置步骤
Stars: ✭ 103 (-11.21%)
Mutual labels:  scss, less, postcss
Modular Css
A streamlined reinterpretation of CSS Modules via CLI, API, Browserify, Rollup, Webpack, or PostCSS
Stars: ✭ 234 (+101.72%)
Mutual labels:  rollup, postcss, css-modules
Bootstrap 4 Utilities
Bootstrap 4 utility classes in LESS CSS for Bootstrap 3 or any other projects.
Stars: ✭ 105 (-9.48%)
Mutual labels:  scss, sass, less
Style Resources Loader
CSS processor resources loader for webpack
Stars: ✭ 214 (+84.48%)
Mutual labels:  scss, sass, less
Typed Scss Modules
🎁 Generate type definitions (.d.ts) for CSS Modules using SCSS
Stars: ✭ 192 (+65.52%)
Mutual labels:  scss, sass, css-modules
Compile Hero
🔰Visual Studio Code Extension For Compiling Language
Stars: ✭ 169 (+45.69%)
Mutual labels:  scss, sass, less
Glup
Some of the gulp tutorial -《gulp笔记》
Stars: ✭ 136 (+17.24%)
Mutual labels:  scss, sass, less
webpack-typescript-react
Webpack 5 boilerplate with support of most common loaders and modules (see tags and description)
Stars: ✭ 185 (+59.48%)
Mutual labels:  less, postcss, css-modules
Styled Components Theme
Defines themes via flexible color selectors for use with styled-components
Stars: ✭ 302 (+160.34%)
Mutual labels:  styles, scss, sass
Three Dots
🔮 CSS loading animations made by single element.
Stars: ✭ 912 (+686.21%)
Mutual labels:  scss, sass, less
Fast
Develop, build, deploy, redeploy, and teardown frontend projects fast.
Stars: ✭ 126 (+8.62%)
Mutual labels:  scss, sass, postcss
Gulp Starter Kit
A simple Gulp 4 Starter Kit for modern web development.
Stars: ✭ 134 (+15.52%)
Mutual labels:  scss, sass, less

rollup-plugin-styles

npm version monthly downloads count required rollup version build status code coverage license financial contributors

🎨 Universal Rollup plugin for styles:

...and more!

Table of Contents

Installation

# npm
npm install -D rollup-plugin-styles
# pnpm
pnpm add -D rollup-plugin-styles
# yarn
yarn add rollup-plugin-styles --dev

Usage

// rollup.config.js
import styles from "rollup-plugin-styles";

export default {
  output: {
    // Governs names of CSS files (for assets from CSS use `hash` option for url handler).
    // Note: using value below will put `.css` files near js,
    // but make sure to adjust `hash`, `assetDir` and `publicPath`
    // options for url handler accordingly.
    assetFileNames: "[name]-[hash][extname]",
  },
  plugins: [styles()],
};

After that you can import CSS files in your code:

import "./style.css";

Default mode is inject, which means CSS is embedded inside JS and injected into <head> at runtime, with ability to pass options to CSS injector or even pass your own injector.

CSS is available as default export in inject and extract modes, but if CSS Modules are enabled you need to use named css export.

// Injects CSS, also available as `style` in this example
import style from "./style.css";
// Using named export of CSS string
import { css } from "./style.css";

In emit mode none of the exports are available as CSS is purely processed and passed along the build pipeline, which is useful if you want to preprocess CSS before using it with CSS consuming plugins, e.g. rollup-plugin-lit-css.

PostCSS configuration files will be found and loaded automatically, but this behavior is configurable using config option.

Importing a file

CSS/Stylus

/* Import from `node_modules` */
@import "bulma/css/bulma";
/* Local import */
@import "./custom";
/* ...or (if no package named `custom` in `node_modules`) */
@import "custom";

Sass/Less

You can prepend the path with ~ to resolve in node_modules:

// Import from `node_modules`
@import "~bulma/css/bulma";
// Local import
@import "./custom";
// ...or
@import "custom";

Also note that partials are considered first, e.g.

@import "custom";

Will look for _custom first (with the approptiate extension(s)), and then for custom if _custom doesn't exist.

CSS Injection

styles({
  mode: "inject", // Unnecessary, set by default
  // ...or with custom options for injector
  mode: [
    "inject",
    { container: "body", singleTag: true, prepend: true, attributes: { id: "global" } },
  ],
  // ...or with custom injector
  mode: ["inject", (varname, id) => `console.log(${varname},${JSON.stringify(id)})`],
});

CSS Extraction

styles({
  mode: "extract",
  // ... or with relative to output dir/output file's basedir (but not outside of it)
  mode: ["extract", "awesome-bundle.css"],
});

Emitting processed CSS

// rollup.config.js
import styles from "rollup-plugin-styles";

// Any plugin which consumes pure CSS
import litcss from "rollup-plugin-lit-css";

export default {
  plugins: [
    styles({ mode: "emit" }),

    // Make sure to list it after this one
    litcss(),
  ],
};

CSS Modules

styles({
  modules: true,
  // ...or with custom options
  modules: {},
  // ...additionally using autoModules
  autoModules: true,
  // ...with custom regex
  autoModules: /\.mod\.\S+$/,
  // ...or custom function
  autoModules: id => id.includes(".modular."),
});

With Sass/Less/Stylus

Install corresponding dependency:

  • For Sass support install node-sass or sass:

    # npm
    npm install -D node-sass
    # pnpm
    pnpm add -D node-sass
    # yarn
    yarn add node-sass --dev
    
    # npm
    npm install -D sass
    # pnpm
    pnpm add -D sass
    # yarn
    yarn add sass --dev
    
  • For Less support install less:

    # npm
    npm install -D less
    # pnpm
    pnpm add -D less
    # yarn
    yarn add less --dev
    
  • For Stylus support install stylus:

    # npm
    npm install -D stylus
    # pnpm
    pnpm add -D stylus
    # yarn
    yarn add stylus --dev
    

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

Sass and fibers

By default, when using Dart Sass implementation, fibers package will be loaded automatically if available, otherwise sync mode will be used for better performance.

When installed via npm, Dart Sass supports a JavaScript API that's fully compatible with Node Sass <...>, with support for both the render() and renderSync() functions. <...>

Note however that by default, renderSync() is more than twice as fast as render() due to the overhead of asynchronous callbacks. To avoid this performance hit, render() can use the fibers package to call asynchronous importers from the synchronous code path.

Source

To install fibers:

# npm
npm install -D fibers
# pnpm
pnpm add -D fibers
# yarn
yarn add fibers --dev

Configuration

See API Reference for Options for full list of available options.

Why

Because alternatives did not look good enough - they are either too basic, too buggy or poorly maintained.

For example, the main alternative (and inspiration) is rollup-plugin-postcss, but at the time it is not actively maintained, has a bunch of critical bugs and subjectively lacks some useful features and quality of life improvements which should be a part of it.

With that said, here is the basic list of things which differentiate this plugin from the aforementioned one:

  • Written completely in TypeScript
  • Up-to-date CSS Modules implementation
  • Built-in @import handler
  • Built-in assets handler
  • Ability to emit pure CSS for other plugins
  • Complete code splitting support, with respect for multiple entries, preserveModules and manualChunks
  • Multiple instances support, with check for already processed files
  • Proper sourcemaps, with included sources content by default
  • Respects assetFileNames for CSS file names
  • Respects sourcemaps from loaded files
  • Support for implementation and fibers forcing for Sass
  • Support for partials and ~ in Less import statements
  • More smaller things that I forgot

License

MIT © Anton Kudryavtsev

Thanks

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