【发布时间】:2015-05-04 18:54:13
【问题描述】:
我正在尝试使用 grunt-depend-concat 在我的 site.js 文件中使用 @depend 标记创建一个包含所有依赖项内容的 site.uncompressed.js 文件。正在创建目标文件,但 @depend cmets 仍位于文件顶部。我是否正确使用了这个 grunt 包?我的代码有问题吗?如果我仍然可以使用@depend 标签,我愿意接受替代的 Grunt 包,但是 grunt 包的文档相当稀疏,我可以弄清楚还有其他方法可以做到这一点。
site.js(部分):
/**
* @depend vendor/jquery-1.11.1.min.js
* @depend vendor/jquery.smooth-scroll-1.4.13.min.js
[…]
*/
[…]
Gruntfile.js:
(function () {
'use strict';
}());
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
filepaths: {
assetDir: 'httpdocs/files/assets/',
jsDir: '<%= filepaths.assetDir %>' + 'js/',
jsSrc: '<%= filepaths.jsDir %>' + 'site.js',
jsComb: '<%= filepaths.jsDir %>' + 'site.uncompressed.js',
jsMin: '<%= filepaths.jsDir %>' + 'site.min.js';
},
'depend-concat': {
depend_doctag: {
options: {
method: {
type: 'doctag',
tag: 'depend'
}
},
src: ['<%= filepaths.jsSrc %>'],
dest: '<%= filepaths.jsComb %>'
},
},
uglify: {
options: {
preserveComments: false,
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */',
sourceMap: true
},
dist: {
files: {
'<%= filepaths.jsMin %>': ['<%= filepaths.jsComb %>']
}
}
}
});
require('load-grunt-tasks')(grunt);
grunt.registerTask('default', ['jshint', 'depend-concat', 'uglify']);
};
咕噜声输出:
运行“jshint:files”(jshint)任务
>> 2 个文件无 lint。
运行“depend-concat:depend_doctag”(depend-concat)任务文件 “httpdocs/files/assets/js/site.uncompressed.js” 已创建。
运行“uglify:dist”(uglify)任务
>> 1 个源图已创建。
>> 创建了 1 个文件。
完成,没有错误。
site.uncompressed.js(部分):
/**
* @depend vendor/jquery-1.11.1.min.js
* @depend vendor/jquery.smooth-scroll-1.4.13.min.js
[…]
*/
【问题讨论】:
标签: gruntjs concatenation