【问题标题】:Visual Studio 2015 autoprefixerVisual Studio 2015 自动前缀
【发布时间】:2016-01-26 22:08:33
【问题描述】:

我发现 Web Essentials 自动前缀不够自动 - 我需要手动说出它来添加前缀。当我写 .less.scss 时,它也不给我提供前缀。

是否有任何扩展或选项可以使其在 .less.scss 阶段的 css 编译中自动添加前缀?

我尝试过 Web Compiler 扩展,但它不支持 sass 的前缀,并说它支持 less 的前缀,但我尝试在编写 .less 时在 compilerconfig.json 中启用 autoprefix,但它没有不要添加任何东西。

Visual Studio 有什么东西吗?或者也许我应该转储它并使用一些编辑器 + gulp?

【问题讨论】:

    标签: visual-studio sass less autoprefixer


    【解决方案1】:

    我确信会有一个扩展,但是创建一个 Grunt/Gulp 文件来为您进行编译并不是太多工作。 Task Runner Explorer 然后将管理文件的运行。编写自己的代码将为您提供扩展程序所不具备的控制力和灵活性。

    这是一个使用 Grunt 的示例,取自我关于主题 Getting started with Grunt, SASS and Task Runner Explorer 的帖子

    module.exports = function (grunt) {
        'use strict';
    
        grunt.loadNpmTasks('grunt-sass');
        grunt.loadNpmTasks('grunt-autoprefixer');
        grunt.loadNpmTasks('grunt-contrib-watch');
    
        grunt.initConfig({
            pkg: grunt.file.readJSON('package.json'),
    
            // Sass
            sass: {
                options: {
                    sourceMap: true, // Create source map
                    outputStyle: 'compressed' // Minify output
                },
                dist: {
                    files: [
                      {
                          expand: true, // Recursive
                          cwd: "sass", // The startup directory
                          src: ["**/*.scss"], // Source files
                          dest: "stylesheets", // Destination
                          ext: ".css" // File extension 
                      }
                    ]
                }
            },
    
            // Autoprefixer
            autoprefixer: {
                options: {
                    browsers: ['last 2 versions'],
                    map: true // Update source map (creates one if it can't find an existing map)
                },
    
                // Prefix all files
                multiple_files: {
                    src: 'stylesheets/**/*.css'
                }, 
            },
    
            // Watch
            watch: {
                css: {
                    files: ['sass/**/*.scss'],
                    tasks: ['sass', 'autoprefixer'],
                    options: {
                        spawn: false
                    }
                }
            }
        });
    
        grunt.registerTask('dev', ['watch']);
        grunt.registerTask('prod', ['sass', 'autoprefixer']);
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多