作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在使用 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'])
}
<!-- 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.
最佳答案
事实证明问题出在 registerTask() 上。您需要显式添加 concat/uglify。所以它应该是这样的: grunt.registerTask('use', ['useminPrepare','usemin','concat','uglify'])
关于gruntjs - 如何从usemin任务中获取输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16682304/
我是一名优秀的程序员,十分优秀!