npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rollup-plugin-lib-styles

v1.2.3

Published

Universal Rollup plugin for styles: PostCSS, Sass, Less, Stylus and more

Downloads

79

Readme

rollup-plugin-lib-styles

npm version required rollup version

🎨 Universal Rollup plugin for styles

...and more!

Table of Contents

Usage

# npm
npm install -D rollup-plugin-lib-styles
# pnpm
pnpm add -D rollup-plugin-lib-styles
# yarn
yarn add rollup-plugin-lib-styles --dev
// rollup.config.js
import styles from "rollup-plugin-lib-styles";

export default {
  plugins: [styles()],
};

CSS Extraction

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

CSS Injection

styles({
  mode: "inject",
  // ...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)})`],
});

preserveStyleModules

export default {
  output: {
    dir: 'es', 
    format: 'es',
    preserveModules: true,
    preserveModulesRoot: 'src',
  },
  plugins: [styles({
    preserveStyleModules: true,
  })],
};

preserveStyleModules ( 仅当output.preserveModules 为 true 时生效)

  • true: 只转换样式文件,不进行合并,同时会在引入样式文件的js模块保留保留引入语句。
  • false: 会将每个js模块引入的所有样式文件合并成一个文件。

CSS Modules

styles({
  modules: true,
  // ...or with custom options
  modules: {
    generateScopedName: '[dir]_[name]_[local]_[hash:6]'
  },
  // ...additionally using autoModules
  autoModules: true, // set by default
  // ...with custom regex
  autoModules: /\.mod\.\S+$/,
  // ...or custom function
  autoModules: id => id.includes(".modular."),
});

PostCSS

Use config file

// postcss.config.js
module.exports = {
  plugins: [
    require('autoprefixer')
  ]
}

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

PostCSS config in plugin call

import autoprefixer from 'autoprefixer';

styles({
  plugins: [
    autoprefixer(),
  ],
})

Emitting processed CSS

// rollup.config.js
import styles from "rollup-plugin-lib-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(),
  ],
};

With Sass/Less/Stylus

Install corresponding dependency:

  • For Sass support install sass or node-sass:

    # npm
    npm install -D sass
    # pnpm
    pnpm add -D sass
    # yarn
    yarn add sass --dev
    # npm
    npm install -D node-sass
    # pnpm
    pnpm add -D node-sass
    # yarn
    yarn add node-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.

Configuration

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

Why

完整继承了rollup-plugin-styles的所有功能。

并做了下列改进:

  • 支持 rollup@3x
  • 修复了 preserveModules + extract 模式下生成的 css 文件被去重的问题。
  • 新增 preserveStyleModules 选项,可以只转换css,不做合并,并且保留 css 文件的引入语句。
  • 修复了 module 选项覆盖 autoModule 的问题。
  • 修改了一些默认选项,更符合使用习惯。
    • mode: extract
    • autoModule: true

License

MIT © MaoLin Xiao

Thanks