【问题标题】:How to get output from usemin task?如何从 usemin 任务中获取输出?
【发布时间】:2013-05-22 01:59:02
【问题描述】:

我目前正在使用 usemin 任务来执行我的 concat 和 uglify 任务。但是,我没有从 concat/uglify 任务中得到任何输出。没有看到任何错误或警告。如何获得结果输出 dist/app/myscript.js 脚本?

Gruntfile.js 如下:

module.exports = function(grunt){
  var paths = {
    app: 'app',
    dist: 'dist'
  };

  grunt.initConfig({
    paths: paths,
    clean: {
      dist: {
        src: ['<%= paths.dist %>']
      }
    },
    copy: {
        dist: {
            files: [
                {expand: true, cwd: '.', src: ['**'], dest: '<%= paths.dist %>/'}
            ]
        }
    },
    useminPrepare: {
      html: '<%= paths.dist %>/<%= paths.app %>/index.html'
    },
    usemin: {
        html: '<%= paths.dist %>/<%= paths.app %>/index.html'
    }
  });

  grunt.loadNpmTasks('grunt-usemin');
  grunt.loadNpmTasks('grunt-contrib-cssmin');
  grunt.loadNpmTasks('grunt-contrib-copy');
  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.registerTask('default', ['clean','copy']);
  grunt.registerTask('use', ['useminPrepare','usemin'])
}

HTML 构建 sn-p:

<!-- build:js myscript.js -->
<script type="text/javascript" src='router.js'></script>
<script type="text/javascript" src='bootstrap.js'></script>
<!-- endbuild -->

控制台输出:

Running "useminPrepare:html" (useminPrepare) task
Going through dist/app/index.html to update the config
Looking for build script HTML comment blocks

Found a block:
<!-- build:js myscript.js -->
<!-- Globals -->
<script type="text/javascript" src='router.js'></script>
<script type="text/javascript" src='bootstrap.js'></script>
<!-- endbuild -->
Updating config with the following assets:
    - dist/app/router.js
    - dist/app/bootstrap.js

Configuration is now:

  cssmin:
  {}

  concat:
  { 'dist/app/myscript.js': 
   [ 'dist/app/router.js',
     'dist/app/bootstrap.js' ] }

  uglify:
  { 'dist/app/myscript.js': 'dist/app/myscript.js' }

  requirejs:
  {}

Running "usemin:html" (usemin) task

Processing as HTML - dist/app/index.html
Update the HTML to reference our concat/min/revved script files
Update the HTML with the new css filenames
Update the HTML with the new img filenames
Update the HTML with data-main tags
Update the HTML with the data tags
Update the HTML with background imgs, case there is some inline style
Update the HTML with anchors images
Update the HTML with reference in input

Done, without errors.

【问题讨论】:

    标签: gruntjs


    【解决方案1】:

    原来问题出在 registerTask() 上。您需要显式添加 concat/uglify。所以它应该是这样的:grunt.registerTask('use', ['useminPrepare','usemin','concat','uglify'])

    【讨论】:

      【解决方案2】:

      从技术上讲,grunt-usemin 还不够成熟,无法在失败时为您提供错误,这是我迄今为止的观察结果。

      它总是显示Processing as HTML, Update the HTML .......,即使它在某处失败。

      让我们回到解决方案,我认为你的 HTML Build sn-p 有问题,你没有提到 myscript.js 之前应该有 app 的正确路径 - &lt;!-- build:js app/myscript.js --&gt;

      如果问题仍未解决,请告诉我。

      【讨论】:

      • 很高兴知道该项目仍处于起步阶段。原来问题出在 registerTask() 上。您需要显式添加 concat/uglify。所以它应该是这样的: grunt.registerTask('use', ['useminPrepare','usemin','concat','uglify'])
      • @sthomps 这就是解决方案,您应该发布并接受答案
      猜你喜欢
      • 1970-01-01
      • 2012-02-14
      • 1970-01-01
      • 1970-01-01
      • 2019-06-20
      • 1970-01-01
      • 2016-03-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多