Laravel elixir and autoprefixer
Asked Answered
F

3

5

So I saw that elixir doesn't automatically use autoprefixer. This is how my gulp file looks:

var Elixir = require('laravel-elixir');
var autoprefixer = require('gulp-autoprefixer');
var gulp = require('gulp');

Elixir.config.sourcemaps = false;

gulp.task('sass', function() {
    return gulp.src('resources/sass/app.scss')
        .pipe(autoprefixer({
            browsers: ['last 2 versions'],
            cascade: false
        }))
        .pipe(gulp.dest('public/css/app.css'));
});

Elixir(function(mix) {

    // Copy bootstrap.min.js to node vendor directory until it becomes a node module
    mix.copy('public/vendor/bootstrap-4', 'node_modules/bootstrap-4');

    // Combine all vendor scripts
    mix.scripts([
        'bootstrap-4/dist/js/bootstrap.min.js',
        'vue/dist/vue.min.js'
    ], 'public/js/vendor.js', 'node_modules');

    // Combine all files into one single CSS file
    mix.task('sass', 'resources/sass/**/*.scss');

    // Get rid of cached version
    mix.version([
        'public/js/vendor.js',
        'public/css/app.css'
    ]);

});

But it's not issuing autoprefixer still. I get no gulp errors. And when I run gulp watch, it doesn't update whenever I update a .scss file. All my sass files are located under resources/sass

Thanks for any help!

I even tried:

new Task('sass', function() {
    return gulp.src('resources/sass/app.scss')
        .pipe(autoprefixer({
            browsers: ['last 2 versions'],
            cascade: false
        }))
        .pipe(gulp.dest('public/css/app.css'));
})
.watch('resources/sass/**/*.scss');
Filtrate answered 10/9, 2015 at 16:32 Comment(2)
Since Bootstrap 4 already has compiled CSS, why not just include that? Otherwise, there's a mix.sass() function you could use instead of creating a new task. Laravel Elixir automatically uses autoprefixer unless you disable it as well. See the following Gulpfile.js example: gist.github.com/divspace/3f952754581babb21c5bMirage
I love when the Laravel docs leave us alone. There's no doc whatsoever on Autoprefixer, but I've asked for that in #372Aeciospore
A
10

Although currently undocumented, Laravel's Elixir indeed runs your CSS through Autoprefixer, with it's mostly default settings, as found in the package's Config.js:

{
    ...
    css: {
        autoprefix: {
            enabled: true,

            options:  {
                browsers: ['last 2 versions'],
                cascade: false
            }
        },
    }
}

To customize that configuration, you should use the following: 

elixir.config.css.autoprefix = {
    enabled: true, //default, this is only here so you know how to disable
    options: {
        cascade: true,
        browsers: ['last 2 versions', '> 1%']
    }
};

elixir(function(mix) {
    ...
});
Aeciospore answered 4/12, 2015 at 23:32 Comment(0)
P
5

use this configurations

var elixir = require('laravel-elixir');
config.css.autoprefix.options.browsers =  ['last 15 versions'] ;

elixir(function(mix) {
    mix.sass('index.scss');
});
Pinnati answered 15/6, 2016 at 17:7 Comment(0)
M
-2

Your gruntfile.js should look like this:

var elixir = require('laravel-elixir');

elixir(function(mix) {
  mix
    .copy('./public/vendor/bootstrap-4', './node_modules/bootstrap-4')
    .sass('app.scss')
    .scripts([
      './node_modules/bootstrap-4/dist/js/bootstrap.js'
      './node_modules/vue/dist/vue.js'
    ], './public/js/app.js')
    .version([
      'css/app.js',
      'js/app.css'
    ]);
});

Your resources/assets/sass/app.scss file should look like this:

@import "node_modules/bootstrap-4/scss/bootstrap";

You'll now have a directory structure like this:

public/build/css/app-**********.css
public/build/css/app.css.map
public/build/js/app-**********.js
public/build/js/app.js.map
public/css/app.css
public/css/app.map
public/js/app.js
public/js/app.map.js

The asterisks will be [a-z0-9]{10} but you'll load them by calling {{ elixir('css/app.css') }} and {{ elixir('js/app.js') }}.

Mirage answered 26/10, 2015 at 23:32 Comment(1)
are you answering the question or trying to teach the guy correct markup?Aeciospore

© 2022 - 2024 — McMap. All rights reserved.