2017-05-31 111 views
2

我有一个GruntJS + SASS指南针的问题。我已经设置了devprod配置。 对于dev css有outputStyle: 'expanded',对于prodoutputStyle: 'compressed'。当我在做prod - 它像一个魅力。在控制台我看到Grunt指南针dev和prod

Running "compass:dist" (compass) task 
overwrite css/screen.css (0.392s) 
Compilation took 0.4s 

css压缩它应该是。

但是当我做dev它显示在控制台没有

Running "compass:dev" (compass) task 

Running "autoprefixer:dist" (autoprefixer) task 

和CSS仍处于压缩状态。

还有就是我Gruntfile.js配置:

module.exports = function(grunt) { 
grunt.initConfig({ 
    pkg: grunt.file.readJSON('package.json'), 

    compass: { 
     dev: { 
      options: { 
       sassDir: 'sass', 
       cssDir: 'css', 
       imagesDir: 'images', 
       fontsDir: 'fonts', 
       relativeAssets: true, 
       boring: true, 
       outputStyle: 'expanded', 
       environment: 'development', 
       raw: 'preferred_syntax = :sass\n' 
      } 
     }, 
     dist: { 
      options: { 
       sassDir: 'sass', 
       cssDir: 'css', 
       imagesDir: 'images', 
       fontsDir: 'fonts', 
       relativeAssets: true, 
       boring: true, 
       force: true, 
       bundleExec: true, 
       outputStyle: 'compressed', 
       environment: 'production', 
       raw: 'preferred_syntax = :sass\n' 
      } 
     } 
    }, 

    autoprefixer: { 
     dist:{ 
      files:{ 
       'css/screen.css':'css/screen.css' 
      } 
     } 
    }, 

    concat: { 
     dist: { 
      src: [ 
       'js/vendors/filename.js', 
       'js/companyname/filename.js' 
      ], 
      dest: 'js/companyname/main.js' 
     } 
    }, 

    jshint: { 
     all: ['Gruntfile.js'], 
     beforeconcat: [ 
      'js/src/companyname/app.js', 
      'js/src/companyname/bar.js' 
     ] 
    }, 

    uglify: { 
     options: { 
      mangle: false 
     }, 
     prod: { 
      files: [{ 
       expand: true, 
       cwd: 'js', 
       src: [ 
        'vendors/**/*.js', 
        'companyname/**/*.js' 
       ], 
       dest: 'js' 
      }] 
     } 
    }, 

    copy: { 
     main: { 
      expand: true, 
      cwd: 'js/src', 
      src: [ 
       'companyname/**/*.js', 
       'vendors/**/*.js' 
      ], 
      dest: 'js/' 
     } 
    }, 

    imagemin: { 
     jpg: { 
      options: { 
       optimizationLevel: 8 
      }, 
      files: [ 
       { 
        expand: true, 
        cwd: 'images-src/', 
        src: ['**/*.jpg'], 
        dest: 'images/', 
        ext: '.jpg' 
       } 
      ] 
     }, 
     png: { 
      options: { 
       optimizationLevel: 8 
      }, 
      files: [ 
       { 
        expand: true, 
        cwd: 'images-src/', 
        src: ['**/*.png'], 
        dest: 'images/', 
        ext: '.png' 
       } 
      ] 
     } 
    }, 

    clean: { 
     images: { 
      src: ['images'] 
     } 
    }, 

    watch: { 
     compass: { 
      files: [ 
       'sass/{,*/}*.sass', 
       'images-src/{,*/}*.{png,jpg,gif}' 
      ], 
      tasks: [ 
       'compass:dev', 
       'autoprefixer', 
       'clean:images', 
       'imagemin' 
      ] 
     } 
    } 
}); 

grunt.loadNpmTasks('grunt-contrib-compass'); 
grunt.loadNpmTasks('grunt-contrib-imagemin'); 
grunt.loadNpmTasks('grunt-contrib-clean'); 
grunt.loadNpmTasks('grunt-contrib-concat'); 
grunt.loadNpmTasks('grunt-contrib-jshint'); 
grunt.loadNpmTasks('grunt-contrib-uglify'); 
grunt.loadNpmTasks('grunt-contrib-copy'); 
grunt.loadNpmTasks('grunt-autoprefixer'); 
grunt.loadNpmTasks('grunt-contrib-watch'); 

grunt.registerTask('default', [ 
    'compass:dev', 
    'autoprefixer', 
    'copy', 
    'concat', 
    'jshint', 
    'uglify' 
]); 

grunt.registerTask('prod', [ 
    'compass:dist', 
    'autoprefixer', 
    'copy', 
    'concat', 
    'jshint', 
    'uglify', 
    'clean:images', 
    'imagemin' 
]); 
}; 

我做错了吗?

回答

1

你可以制作两个不同的指南针开发者。

compass: { 
    dev: { 
    ... 
    force: true 
    ... 
    }, 
    devWatch: { 
    ... ur original ... 
    } 
} 

watch(compass: {tasks: ['compass:devWatch', ...]}) 

grunt.registerTask('watch', [ 
    'compass:dev', 
    'watch' 
]); 

grunt.registerTask('dev', [ 
    'compass:dev' 
]); 
+0

非常感谢!你的回答帮助我找到了一个错误。我忘了为开发任务添加'force:true'。其余的就像魅力一样。 – Oleg