GithubHelp home page GithubHelp logo

webcoding / postcss-partial-import Goto Github PK

View Code? Open in Web Editor NEW

This project forked from csstools/postcss-partial-import

0.0 1.0 0.0 53 KB

Inline sugary @import statements in CSS

License: Other

JavaScript 48.39% CSS 51.61%

postcss-partial-import's Introduction

Partial Import

NPM Version Build Status

Partial Import inlines @import statements in CSS.

Partial Import allows partial imports like Sass. It finds stylesheets within npm and Bower packages. It can even generate imports if they don’t already exist.

/* before: foo/_bar.css */

html {
    background-color: #fafafa;
}

/* before: file.css */

@import "foo/bar";

/* after file.css */

html {
    background-color: #fafafa;
}

Usage

Add Partial Import as a dependency:

npm install postcss-partial-import --save-dev

Node Usage

require('postcss-partial-import')({ /* options */ }).process(YOUR_CSS);

PostCSS and CLI Usage

Add PostCSS as a dependency:

npm install postcss --save-dev

Use Partial Import as a PostCSS plugin:

postcss([
    require('postcss-partial-import')({ /* options */ })
]);

Or, use Partial Import as a PostCSS plugin from the CLI:

postcss --use postcss-partial-import input.css

# or, use a json configuration
postcss --config my-postcss-config.json input.css
{
  "use": ["postcss-partial-import"]
}

Gulp Usage

Add Gulp PostCSS as a dependency:

npm install gulp-postcss --save-dev

Use Partial Import in your Gulpfile:

var postcss = require('gulp-postcss');

gulp.task('css', function () {
    return gulp.src('./css/src/*.css').pipe(
        postcss([
            require('postcss-partial-import')({ /* options */ })
        ])
    ).pipe(
        gulp.dest('./css')
    );
});

Grunt Usage

Add Grunt PostCSS as a dependency:

npm install grunt-postcss --save-dev

Use Partial Import in your Gruntfile:

grunt.loadNpmTasks('grunt-postcss');

grunt.initConfig({
    postcss: {
        options: {
            processors: [
                require('postcss-partial-import')({ /* options */ })
            ]
        },
        dist: {
            src: 'css/*.css'
        }
    }
});

Options

encoding

Type: String
Default: utf8

The character encoding of files being imported.

extension

Type: String
Default: .css

The file extension appended to partials being imported.

prefix

Type: String
Default: _

The leading characters prepended to partials being imported.

generate

Type: Boolean
Default: false

Whether partials should be generated if they do not already exist.

dirs

Type: Array
Default: []

A list of alternate directories to find partials in.

plugins

Type: Array
Default: []

A list of PostCSS plugins to run over individual partials.

addDependencyTo

Type: function
Default: null

To pass CSS @import files to a compiler (such as webpack), which would otherwise not know which CSS files to watch for browser reloading.

Example

// webpack.config.js
postcss: function(webpack) {
    return [
        require('postcss-partial-import')({
        	addDependencyTo: webpack
        })
    ];
}

resolve

Type: function Default: null

Overrides the default function for resolving paths. The function will fall back to the default resolving behaviour if nothing is returned. The function will receive four arguments:

  • id: The @import string to be resolved
  • dir: The directory of the source file
  • options: All options passed in to the plugin

postcss-partial-import's People

Contributors

jonathantneal avatar andyjansson avatar trysound avatar cookpete avatar snuggs avatar meastes avatar

Watchers

James Cloos 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.