Gruntjs 如何从usemin任务中获取输出?

Gruntjs 如何从usemin任务中获取输出?,gruntjs,Gruntjs,我目前正在使用usemin任务来执行concat和uglify任务。但是,我没有从concat/uglify任务中获得任何输出。没有看到任何错误或警告。如何获取结果输出dist/app/myscript.js脚本 Gruntfile.js如下所示: module.exports = function(grunt){ var paths = { app: 'app', dist: 'dist' }; grunt.initConfig({ paths: path

我目前正在使用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'])
}
module.exports=函数(grunt){
变量路径={
应用程序:“应用程序”,
dist:“dist”
};
grunt.initConfig({
路径:路径,
清洁:{
地区:{
src:['']
}
},
副本:{
地区:{
档案:[
{expand:true,cwd:'.',src:['**'],dest:'/'}
]
}
},
使用准备:{
html:“//index.html”
},
usemin:{
html:“//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”);
registerTask('default',['clean','copy']);
registerTask('use',['useminPrepare','usemin']))
}
HTML生成代码段:

<!-- 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.
运行“useminPrepare:html”(useminPrepare)任务
通过dist/app/index.html更新配置
正在查找生成脚本HTML注释块
找到一个块:
使用以下资产更新配置:
-dist/app/router.js
-dist/app/bootstrap.js
现在的配置是:
cssmin:
{}
康卡特:
{'dist/app/myscript.js':
['dist/app/router.js',
'dist/app/bootstrap.js']}
丑陋的:
{'dist/app/myscript.js':'dist/app/myscript.js'}
要求:
{}
正在运行“usemin:html”(usemin)任务
作为HTML处理-dist/app/index.HTML
更新HTML以引用我们的concat/min/revved脚本文件
用新的css文件名更新HTML
使用新的img文件名更新HTML
使用数据主标记更新HTML
使用数据标记更新HTML
使用背景IMG更新HTML,以防出现一些内联样式
使用锚定图像更新HTML
使用输入中的引用更新HTML
完成,没有错误。

从技术上讲
grunt usemin
还不够成熟,如果失败了,会给你错误,这是我到目前为止的观察结果

它总是将
处理显示为HTML,更新HTML……
即使它在某个地方失败了

让我们回到解决方案上来,我认为您的HTML构建代码片段中存在问题,您没有提到myscript.js之前应该有app的正确路径-


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

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

很高兴知道这个项目还处于初级阶段。原来问题出在registerTask()上。您需要显式添加concat/uglify。所以它应该是这样的:grunt.registerTask('use',['useminPrepare','usemin','concat','uglify'])@sthomps这是解决方案,你应该发布并接受答案