Gathering detailed insights and metrics for rollup-plugin-styles
Gathering detailed insights and metrics for rollup-plugin-styles
Gathering detailed insights and metrics for rollup-plugin-styles
Gathering detailed insights and metrics for rollup-plugin-styles
postcss-nested-once
Postcss plugin to unwrap nested rules (like how Sass does it), compatible with rollup-plugin-styles
@ironkinoko/rollup-plugin-styles
Universal Rollup plugin for styles: PostCSS, Sass, Less, Stylus and more
@rollup/plugin-commonjs
Convert CommonJS modules to ES2015
@rollup/plugin-node-resolve
Locate and bundle third-party dependencies in node_modules
npm install rollup-plugin-styles
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
246 Stars
478 Commits
42 Forks
3 Watching
12 Branches
12 Contributors
Updated on 04 Nov 2024
Minified
Minified + Gzipped
TypeScript (87.37%)
JavaScript (8.8%)
CSS (1.57%)
SCSS (1.51%)
Less (0.37%)
Stylus (0.18%)
Shell (0.13%)
Sass (0.07%)
Cumulative downloads
Total Downloads
Last day
10.7%
8,986
Compared to previous day
Last week
-0.9%
45,848
Compared to previous week
Last month
5.1%
231,554
Compared to previous month
Last year
8.4%
2,671,253
Compared to previous year
18
1
53
@import
statements inside regular CSS...and more!
1# npm 2npm install -D rollup-plugin-styles 3# pnpm 4pnpm add -D rollup-plugin-styles 5# yarn 6yarn add rollup-plugin-styles --dev
1// rollup.config.js 2import styles from "rollup-plugin-styles"; 3 4export default { 5 output: { 6 // Governs names of CSS files (for assets from CSS use `hash` option for url handler). 7 // Note: using value below will put `.css` files near js, 8 // but make sure to adjust `hash`, `assetDir` and `publicPath` 9 // options for url handler accordingly. 10 assetFileNames: "[name]-[hash][extname]", 11 }, 12 plugins: [styles()], 13};
After that you can import CSS files in your code:
1import "./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.
1// Injects CSS, also available as `style` in this example 2import style from "./style.css"; 3// Using named export of CSS string 4import { 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.
1/* Import from `node_modules` */ 2@import "bulma/css/bulma"; 3/* Local import */ 4@import "./custom"; 5/* ...or (if no package named `custom` in `node_modules`) */ 6@import "custom";
You can prepend the path with ~
to resolve in node_modules
:
1// Import from `node_modules` 2@import "~bulma/css/bulma"; 3// Local import 4@import "./custom"; 5// ...or 6@import "custom";
Also note that partials are considered first, e.g.
1@import "custom";
Will look for _custom
first (with the appropriate extension(s)), and then for custom
if _custom
doesn't exist.
1styles({ 2 mode: "inject", // Unnecessary, set by default 3 // ...or with custom options for injector 4 mode: [ 5 "inject", 6 { container: "body", singleTag: true, prepend: true, attributes: { id: "global" } }, 7 ], 8 // ...or with custom injector 9 mode: ["inject", (varname, id) => `console.log(${varname},${JSON.stringify(id)})`], 10});
1styles({ 2 mode: "extract", 3 // ... or with relative to output dir/output file's basedir (but not outside of it) 4 mode: ["extract", "awesome-bundle.css"], 5});
1// rollup.config.js 2import styles from "rollup-plugin-styles"; 3 4// Any plugin which consumes pure CSS 5import litcss from "rollup-plugin-lit-css"; 6 7export default { 8 plugins: [ 9 styles({ mode: "emit" }), 10 11 // Make sure to list it after this one 12 litcss(), 13 ], 14};
1styles({ 2 modules: true, 3 // ...or with custom options 4 modules: {}, 5 // ...additionally using autoModules 6 autoModules: true, 7 // ...with custom regex 8 autoModules: /\.mod\.\S+$/, 9 // ...or custom function 10 autoModules: id => id.includes(".modular."), 11});
Install corresponding dependency:
For Sass
support install sass
or node-sass
:
1# npm 2npm install -D sass 3# pnpm 4pnpm add -D sass 5# yarn 6yarn add sass --dev
1# npm 2npm install -D node-sass 3# pnpm 4pnpm add -D node-sass 5# yarn 6yarn add node-sass --dev
For Less
support install less
:
1# npm 2npm install -D less 3# pnpm 4pnpm add -D less 5# yarn 6yarn add less --dev
For Stylus
support install stylus
:
1# npm 2npm install -D stylus 3# pnpm 4pnpm add -D stylus 5# yarn 6yarn add stylus --dev
That's it, now you can import .scss
.sass
.less
.styl
.stylus
files in your code.
See API Reference for Options
for full list of available options.
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:
@import
handlerpreserveModules
and manualChunks
assetFileNames
for CSS file names~
in Less import statementsMIT © Anton Kudryavtsev
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 5/30 approved changesets -- score normalized to 1
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
27 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More