8

必要に応じて、縮小ファイルのみの uglify タスクの構成を変更する必要があります (ここで jshint タスクについて説明したように: https://github.com/gruntjs/grunt-contrib-watch#compiling-files-as-needed )

変更は jshint タスクではうまく機能しますが、uglify では機能しません。問題はプロパティ パスだと思います...

どんな助けでも大歓迎です;)

ここに私の Gruntfile.js があります:

module.exports = function (grunt) {
    grunt.initConfig({

        // define source files and their destinations
        jshint: {
            all: ['dev/**/*.js'],
        },
        uglify: {
            dynamic_mappings: {
              // Grunt will search for "**/*.js" under "dev/" when the "minify" task
              // runs and build the appropriate src-dest file mappings then, so you
              // don't need to update the Gruntfile when files are added or removed.
            files: [{
                  expand: true,     // Enable dynamic expansion.
                  cwd: 'dev/',      // Src matches are relative to this path.
                  src: ['**/*.js'], // Actual pattern(s) to match.
                  dest: 'build',   // Destination path prefix.
                  ext: '.min.js',   // Dest filepaths will have this extension.
                },
              ],
            }
        }
        watch: {
        options: { spawn: false },
            js:  { files: 'dev/**/*.js', tasks: [ 'uglify' ] },
        }
    });

    // load plugins
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-jshint');

    // default task
    grunt.registerTask('default', [ 'watch' ]);

    grunt.event.on('watch', function(action, filepath) {
        grunt.config(['jshint', 'all'], filepath);
        grunt.config('uglify.dynamic_mappings.files', [{src: filepath }]);
    });

};
4

2 に答える 2

0

yeoman の各 "grunt build" で既に縮小されているものを縮小しない方法

   uglify:        {
      onlyScripts: {
        files:   [{
          dest: '<%= yeoman.dist %>/scripts/scripts.js',
          src:  ['.tmp/concat/scripts/scripts.js']
        }]
      }
    }

また、uglify は一時フォルダーから vendor.js をコピーしないようになったため、「vendorJS」セクションを「copy」タスクに追加します。

copy:
      //...
      vendorJS: {
        expand: true,
        cwd:    '.tmp/concat/scripts/',
        dest:   '<%= yeoman.dist %>/scripts/',
        src:    'vendor.js'
      }

次に、「ビルド」タスクで、uglify のターゲットを「onlyScripts」に設定し、vendor.js をコピーします。

  grunt.registerTask('build', [
    'jshint',
    'clean:dist',
    //'wiredep',
    // ...
    'useminPrepare',
    //'concurrent:dist',
    'autoprefixer',
    'concat',
    'ngAnnotate',
    'copy:dist',
    'cssmin',
    'uglify:onlyScripts',
    'copy:vendorJS',
   // ...
  ]);

http://eugenioz.blogspot.in/2014/08/how-to-not-minify-already-minified-on.html

于 2015-07-22T12:43:55.710 に答える