【问题标题】:after compiling sass using laravel mix only webkit is shown使用 laravel mix 编译 sass 后,只显示 webkit
【发布时间】:2018-01-20 23:36:48
【问题描述】:

我在 mixin 中使用了以下 scss 代码,但编译后 -moz- 和 -o- 供应商前缀未显示在已编译的 css 文件中。

@mixin transition($move) {

     -webkit-transition: $move;
      -moz-transition: $move;
      -o-transition: $move;
      transition: $move;
    }

    a {
      &:hover, &:focus {
        color: $brand-color;
      }
      @include transition(all 0.2s linear);
    }

使用 mix 编译后:

a {
  -webkit-transition: all 0.2s linear;
  transition: all 0.2s linear;
}

a:hover,
a:focus {
  color: #4676fa;
}

提前致谢。 :)

【问题讨论】:

    标签: css laravel sass laravel-mix


    【解决方案1】:

    这是因为 laravel 使用 autoprefixer 根据浏览器版本限制添加/删除供应商前缀。现在几乎所有浏览器都支持transition

    你可以看到转换支持here

    因此,删除无用代码会减小包大小。

    如果您真的想支持旧版浏览器,请设置此配置。

    对于 Laravel Mix(最新)

    将此代码添加到您的 webpack.mix.js 之上。

    let mix = require('laravel-mix');
    
    mix.options({
        postCss: [
            require('autoprefixer')({
                browsers: ['last 40 versions'],
            })
        ]
    });
    
    ...
    ...
    

    对于 Laravel Elixir

    将此代码添加到您的 gulpfile.js 之上

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

    【讨论】:

      猜你喜欢
      • 2020-08-04
      • 2017-11-02
      • 2021-06-16
      • 2018-01-22
      • 1970-01-01
      • 2019-07-01
      • 1970-01-01
      • 2020-12-15
      • 2022-01-03
      相关资源
      最近更新 更多