Giter VIP home page Giter VIP logo

inline-css-brunch's Introduction

inline-css-brunch

Brunch plugin to read your CSS files as strings in JS. This is useful for frameworks like Angular 2 so you don't need to make separate requests for styles.

As of version 2.0.0 of this plugin, it requires Brunch 2.6 or later.

Install

npm install -D inline-css-brunch

Configuration

As of version 2.0.0, you can configure where the plugin is used.

exports.config = {
  plugins: {
    inlineCss: {
      passthrough: /^(node_modules)|(app\/styles)/
    }
  }
}

pattern

Similar to other plugins, this defines which files Brunch will send to this plugin. If you want it to only handle CSS files from a particular part of your app, this will do it. This value can be a string with wildcards or a RegExp or any array of those things.

passthrough

By default this plugin will create wrapped JS modules out of your CSS strings, however, if you want some of your CSS files to be sent to the stylesheets output, you can do that with this option.

Anything matching this string/RegExp/array will not be wrapped as a JS module, but instead added to the output stylesheets.

By default, this plugin will passthrough anything in the node_modules folder. This allows it to be used with the npm.styles config option.

If you don't want anything to passthrough, you can pass false for this option. However, npm.styles will not work in that case.

This behaviour means you don't need to include css-brunch in addition to this one. Unless you want the CSS modules.

html

If defined and true will cause this plugin to inline .html files as well. This can save you needing to install html-brunch. Bear in mind that this plugin exports the string directly from the module while html-brunch wraps it in a function. This isn't a drop-in replacement.

If a pattern is specified, this parameter will have no effect and you'll need to adjust your pattern to include .html files.

Usage

const myCssString = require('./my-css-file.css');

If you have JS/TS files with the same base name as your CSS files, and you want to refer to those files without their extension, you will probably need to include this in your config file:

exports.config = {
  files: {
    javascripts: {
      order: {
        after: [/\.css$/]
      }
    }
  }
}

This will force your CSS files to be output later in the file, which means they won't take the alias for the base name.

inline-css-brunch's People

Contributors

colinbate avatar

Watchers

 avatar  avatar  avatar

Forkers

cepinos khoden

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.