Git Product home page Git Product logo

Comments (10)

RickCogley avatar RickCogley commented on June 2, 2024 8

Fwiw, here's my gist of my gulpfile.js, showing how to call postcss-import to inline your @import css files.

https://gist.github.com/cf7e5174652e73cf1059

from postcss-import.

hisnameisjimmy avatar hisnameisjimmy commented on June 2, 2024 4

Hello from the future. I used your stuff to improve my stuff and fix some problems I was having with PostCSS import stuff.

Hopefully this helps future web travelers.

var gulp    = require('gulp');
var gutil   = require('gulp-util');

// Load plugins:
var plugins = require('gulp-load-plugins')({
  pattern: [
    'gulp-*',
    'gulp.*',
    'browserify',
    'babelify',
    'vinyl-source-stream',
    'vinyl-buffer',
    'browser-sync',
    'autoprefixer',
  ]
});

// Source and destination paths for tasks:
var path = {
  src:   'app/src',
  dest:  'app/public',
  npm:   'node_modules',
};

var atImport = require("postcss-import")

gulp.task('styles', function () {
  var postcssplugins = [
    atImport(),
    // Autoprefix:
    plugins.autoprefixer({
      browsers: [
        'last 3 versions',
        'ie 8',
        'ie 9'
      ]
    })
  ];
  return gulp.src(path.src + '/styles/main.css')
    .pipe(plugins.postcss(postcssplugins))
    // Write main.css
    .pipe(gulp.dest(path.dest + '/styles'))
    .pipe(plugins.browserSync.stream())
    // Report file size:
    .pipe(plugins.size({ showFiles: true }))
    // Minify main.css and rename it to 'main.min.css':
    .pipe(plugins.cssnano())
    .pipe(plugins.rename({suffix: '.min'}))
    .pipe(plugins.size({ showFiles: true }))
    .pipe(gulp.dest(path.dest + '/styles'))
    .pipe(plugins.gzip())
    .pipe(plugins.rename('main.min.gz.css'))
    .pipe(plugins.size({ showFiles: true }))
    .pipe(gulp.dest(path.dest + '/styles'))
    .pipe(plugins.browserSync.stream())
    .on('error', gutil.log);
});

from postcss-import.

jednano avatar jednano commented on June 2, 2024

Refer to https://github.com/postcss/postcss#usage

from postcss-import.

MoOx avatar MoOx commented on June 2, 2024

Just use it as the first plugin of your plugins list. See gulp-postcss.

from postcss-import.

jitendravyas avatar jitendravyas commented on June 2, 2024

I checked Postcss and Gulp-Postcss github pages and I'm still confused.

Below is a part of my gulpfile.js. Can you help me how to use PostCSS-Import to compile app.css

'use strict';

var browserSync = require("browser-sync").create(),
    concat      = require('gulp-concat'),
    del         = require('del'),
    fs          = require('fs'),
    gulp        = require('gulp'),
    intercept   = require('gulp-intercept'), 
    path        = require("path"),
    plumber     = require('gulp-plumber'),
    rename      = require("gulp-rename"),
    runSequence = require('run-sequence'), 
    postcss     = require('gulp-postcss'),
    sass        = require('gulp-sass'),



gulp.task('sass-app', function() {
//   I will import other css files using @import in app.css
    gulp.src('./source/assets/scss/app.css')
        .pipe(plumber())
        .pipe(
          postcss([
            require('autoprefixer')({ browsers: ['last 2 versions'] }),
            require('postcss-simple-vars')({ silent: true })

            ]))
        .pipe(gulp.dest('./css/'))
        .on('end', function(){
            if(isWatching){
                // Only concat if we are watching
                runSequence('css-concat');
            }
        });
});


gulp.task('default', function(callback){
    runSequence(
            'sass-app'

        callback
    );
});

from postcss-import.

MoOx avatar MoOx commented on June 2, 2024

Please read carefully the comment above yours.

from postcss-import.

NetanelBasal avatar NetanelBasal commented on June 2, 2024

Thanks!

from postcss-import.

RickCogley avatar RickCogley commented on June 2, 2024

@NetanelBasal no problem. I struggled to find something relatively complete, but, the examples I found are variously partial. Actually I found a Japanese blog post (I'm based in Japan) about postcss-import, which gave me the hint I needed to finally get the inlining working. If you write all your css without import commands, you're fine, but the first time you try to use a library, like one from npm or bower, you find that they often use @import, which you really need an inlining solution to get working right in your pipeline.

from postcss-import.

RickCogley avatar RickCogley commented on June 2, 2024

By the way I did try using npm scripts directly, but, I discovered these are essentially shell scripts, so you have all the typical issues you have when pipelining in a bash script or at the *sh/ cli.

from postcss-import.

NetanelBasal avatar NetanelBasal commented on June 2, 2024

Great, thanks for the information 😄

from postcss-import.

Related Issues (20)

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.