usemin定义自定义步骤选项

Ren*_*aud 5 uglifyjs gruntjs grunt-usemin

我有一个运行concat的gruntfile和带有特定选项的uglify(即mangle toplevel变量),然后我使用sed来更新index.html中对缩小文件的引用.由于sed,这个解决方案有效但不易维护.我试图使用usemin,但我无法弄清楚如何用uglifyjs的正确选项定义我自己的自定义步骤,而doco缺乏示例来做到这一点.我尝试使用之前写过的相同的uglify任务:

   uglify: {
      options: {
        banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n',
        mangle: {
            except: ['$', 'd3'],
            toplevel: true
        }
      },
      build: {
        src: 'demo/js/<%= pkg.name %>.js',
        dest: 'demo/js/<%= pkg.name %>.min.js'
      }
    },
    useminPrepare : {
        html : 'src/index.html',
        options: {
            flow: {
                steps: {'js' : ['uglify'] }
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

但我收到这个错误:

Warning: Cannot find module 'path-to-module\node_modules\grunt-usemin\lib\config\uglify' Use --force to continue.

是否可以这样做,如果是这样,我在这里做错了什么?

rha*_*per 7

尝试更换uglifyuglifyjs您的流选项.