如何在grunt构建中跳过concat

时间:2017-03-06 10:12:37

标签: javascript angularjs gruntjs uglifyjs grunt-contrib-concat

我需要跳过grunt构建的concat,因为它会导致很多错误,并且在我的角度项目中会发生冲突。

我在Gruntfile.js上试过这个:

copy: {
      dist: {
        files: [{
          expand: true,
          dot: true,
          cwd: '<%= yeoman.app %>',
          dest: '<%= yeoman.dist %>',
          src: [
            '*.{ico,png,txt}',
            '*.html',
            'images/{,*/}*.{webp}',
            'styles/fonts/{,*/}*.*'
          ]
        }, {
          expand: true,
          cwd: '.tmp/images',
          dest: '<%= yeoman.dist %>/images',
          src: ['generated/*']
        },{
          expand: true,
          cwd: '.tmp/scripts',
          dest: '<%= yeoman.dist %>/scripts',
          src: ['<%= yeoman.app %>/scripts/{,*/}*.js']
        }, {
          expand: true,
          cwd: 'bower_components/bootstrap/dist',
          src: 'fonts/*',
          dest: '<%= yeoman.dist %>'
        }]
      },
      styles: {
        expand: true,
        cwd: '<%= yeoman.app %>/styles',
        dest: '.tmp/styles/',
        src: '{,*/}*.css'
      }
    },

useminPrepare: {
      html: '<%= yeoman.app %>/index.html',
      options: {
        dest: '<%= yeoman.dist %>',
        flow: {
          html: {
            steps: {
              js: ['uglifyjs'],
              css: ['cssmin']
            },
            post: {}
          }
        }
      }
    },

  grunt.registerTask('build', [
    'clean:dist',
    'wiredep',
    'useminPrepare',
    'postcss',
    'ngtemplates',
    'ngAnnotate',
    'copy:dist',
    'cdnify',
    'cssmin',
    'uglify',
    'filerev',
    'usemin',
    'htmlmin'
  ]);

但仍然给我输出concat脚本uglify。

1 个答案:

答案 0 :(得分:2)

创建你自己的任务,将运行ngAnnotate然后uglify和cssmin来缩小css。

您还可以指定要在grunt.initConfig上进行uglify和注释的js文件:

ngAnnotate : {
    dist: {
        files: {
            '.tmp/scripts/MYFILE.min.js' : ['app/scripts/MYFILE.js'],
             /*...*/

它是一个较低的版本,而且是更多静态的grunt构建,但它会对你的项目进行缩小和注释。