我正在学习/设置我的项目工作流程,我一直在试图弄清楚为什么grunt-banner options.process()devDependency将后续文件名添加到项目文件中,见下文。 / p>
关于grunt-banner的Gruntfile.js任务的片段:
// Banner inserted at top of the generated files, such a minified CSS
banner: '/**\n' +
' * <%= pkg.name %> - Version <%= pkg.version %>\n' +
' * <%= pkg.description %>\n' +
' * Author: <%= pkg.author.name %> - <%= pkg.author.email %>\n' +
' * Build date: <%= grunt.template.today("yyyy-mm-dd HH:MM:ss") %>\n' +
' * Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.company %>\n' +
' * Released under the <%= pkg.license %> license\n' +
' */\n',
usebanner: {
dist: {
options: {
position: 'top',
banner: '<%= banner %>',
linebreak: true,
process: function( filepath ) {
var ndx = 4;
var file = " * File: <%= filename %>\n *";
var banner = this.banner;
banner = [banner.slice(0, ndx), file, banner.slice(ndx)].join('');
return grunt.template.process(
banner,
{ data: {
filename: filepath.match(/\/([^/]*)$/)[1]
} } );
}
},
files: {
src: [ './build/**/*.js', './build/**/*.css' ]
}
}
},
包含的options.process()采用我的默认横幅并根据我调用的横幅任务插入文件名。有时我只会使用默认横幅,如果你想知道为什么它在那里而不是在options.process()。
横幅正确放置在第一个文件script.js中:
/**
* File: script.js
*
* Project - Version 0.1.0
* Grunt deployed project.
* Author: Someone - some@one.com
* Build date: 2014-06-18 17:33:10
* Copyright (c) 2014 Company
* Released under the MIT license
*/
function test(){
}
但是,在后续文件中,文件名开始堆叠:
/**
* File: master.css
* * File: script.js
*
* Project - Version 0.1.0
* Grunt deployed project.
* Author: Someone - some@one.com
* Build date: 2014-06-18 17:33:10
* Copyright (c) 2014 Company
* Released under the MIT license
*/
@media -sass-debug-info{filename{font-family:file\:\/\/D\:\/htdocs\/project\/dev\/scss\/master\.scss}line{font-family:\0000320}}
html {
background: #f4f4f4;
}