Giter Site home page Giter Site logo

norserium / rollup-plugin-merge-and-inject-css Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 2.0 38 KB

Rollup plugin to merge CSS into the single style and append to the top of styles block

License: MIT License

JavaScript 100.00%
rollup css plugin rollup-plugin merge inject

rollup-plugin-merge-and-inject-css's Introduction

rollup-plugin-merge-and-inject-css

A rollup plugin to collect and combine all the imported css file and inject them to the head at the top of style blocks list.

NPM JavaScript Style Guide

Install

npm install --save-dev rollup-plugin-merge-and-inject-css
yarn add rollup-plugin-merge-and-inject-css --dev

Plugin options

Name Type Required Description
id String false The id of your rollup build, it's needed to update build properly in watch mode. Default value is the random uid for a current watch run.

Usage

The common scenario for using this plugin is the merging of css files produced by different component. For example, it's useful for rollup-plugin-vue.

The default inject tool of this plugin will produce something like that:

  <style>
    .red-component {
      color: red;
    }
  </style>
  <style>
    .blue-component {
      color: blue;
    }
  </style>
  <style>
    .green-component {
      color: green;
    }
  </style>

This plugin will produce this (if all that components are the part of a generating bundle):

  <style>
    /*for=example-components*/
    .red-component {
      color: red;
    }
    .blue-component {
      color: blue;
    }
    .green-component {
      color: green;
    }
  </style>

Example

The example of the rollup config with this plugin

import autoprefixer from 'autoprefixer';
import Vue from 'rollup-plugin-vue';
import babel from 'rollup-plugin-babel';
import commonjs from 'rollup-plugin-commonjs';
import external from 'rollup-plugin-peer-deps-external';
import postcss from 'rollup-plugin-postcss';
import resolve from 'rollup-plugin-node-resolve';
import url from 'rollup-plugin-url';
import sass from 'rollup-plugin-sass';
import css from 'rollup-plugin-merge-and-inject-css'

import pkg from './package.json';

export default {
  input: 'src/index.js',
  output: [
    {
      file: pkg.main,
      format: 'cjs',
      sourcemap: true
    },
    {
      file: pkg.module,
      format: 'es',
      sourcemap: true
    }
  ],
  plugins: [
    external(),
    css({
      id: 'example-components'
    }),
    Vue({
      css: false,
      style: {
        postcssPlugins: [autoprefixer]
      }
    }),
    url(),
    babel({
      exclude: 'node_modules/**',
    }),
    resolve(),
    commonjs(),
  ]
}

rollup-plugin-merge-and-inject-css's People

Contributors

dependabot[bot] avatar norserium avatar yurigor avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.