Comments (10)
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.
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.
Refer to https://github.com/postcss/postcss#usage
from postcss-import.
Just use it as the first plugin of your plugins list. See gulp-postcss.
from postcss-import.
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.
Please read carefully the comment above yours.
from postcss-import.
Thanks!
from postcss-import.
@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.
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.
Great, thanks for the information 😄
from postcss-import.
Related Issues (20)
- Issue with `@layer`s HOT 12
- Plugin is stripping the layer off of a remote url import HOT 1
- Incorrect media query concats HOT 8
- Mention postcss-import-url in docs? HOT 3
- Use the dedicated PostCSS API for errors HOT 2
- Document that all forms of `url` are supported
- Plugins docs HOT 5
- Not able to use postcss-import. Giving error ->Unable to resolve @import "variables.css" HOT 1
- Failed to find file HOT 5
- How to deal with SCSS syntax ? HOT 12
- import inside a selector HOT 1
- Supports at rule not working
- Ignored imports cause re-ordering of CSS HOT 2
- URL's with a fragment or query aren't skipped and give a file not found error HOT 1
- Ignore comments for "postcss-import: `@charset` must precede all other statements" HOT 2
- Drop old Node version support
- Fails with `postcss` 8.4.33, `original.line and original.column are not numbers` HOT 2
- Emitted `@media` AtRules are invalid HOT 4
- Default Imports HOT 3
- Support a way to process a URL with fragments HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from postcss-import.