Gruntjs Grunt-Uglify的动态映射和Concat

Gruntjs Grunt-Uglify的动态映射和Concat,gruntjs,grunt-contrib-uglify,Gruntjs,Grunt Contrib Uglify,我正试图用Grunt Uglify来使用和压缩Javascript文件 我有以下问题,但工作不正常 以下是我的文件夹结构: javascript |- account |- custom.js |- bills |- billing-one.js |- billing-two.js |- test (output folder) 以下是我所期待的: javascript |- account |-

我正试图用Grunt Uglify来使用和压缩Javascript文件

我有以下问题,但工作不正常

以下是我的文件夹结构:

javascript
    |- account
        |- custom.js
    |- bills
        |- billing-one.js
        |- billing-two.js
    |- test (output folder)
以下是我所期待的:

javascript
    |- account
        |- custom.js
    |- bills
        |- billing-one.js
        |- billing-two.js
    |- test
        |- billing-one.min.js (this file includes billing-one.js AND custom.js)
        |- billing-two.min.js (this file includes billing-two.js AND custom.js)
这就是我目前得到的:

javascript
    |- account
        |- custom.js
    |- bills
        |- billing-one.js
        |- billing-two.js
    |- test
        |- bills
            |- billing-one.min.js (this file includes just billing-one.js)
            |- billing-two.min.js (this file includes just billing-two.js)
        |- account 
            |- custom.min.js (this file includes just custom.js)
它不包括custom.js文件,而是创建了两个文件夹
test/account/custom.min.js
“test/bills/billing one.js”-见上文

options: {
    beautify: true,
    mangle: false,
    compress: false,
    preserveComments: 'all'
},
files: [
  {
    expand: true,     // Enable dynamic expansion.
    cwd: 'javascript/',      // Src matches are relative to this path.
    src: [[bills/*.js'], 'account/custom.js'], // Actual pattern(s) to match.
    dest: 'test/',   // Destination path prefix.
    ext: '.min.js',   // Dest filepaths will have this extension.
    extDot: 'first'   // Extensions in filenames begin after the first dot
  },
],
我希望
bills/
文件夹中的所有Javascript文件都包含custom.js

因此,如果有两个文件:
bills/billing one.js
bills/billing two.js

我希望测试/文件夹包括

test/billing one.min.js
(此文件将包含billing one+custom.js)
test/billing two.min.js
(此文件将包含billing two+custom.js)

我不想硬编码文件名。如果将更多文件添加到
bills/
文件夹中,则应将其压缩并输出到
test/
文件夹

非常感谢您的帮助

自接受答案后更新:

使用下面更新的代码来确保它按预期工作-否则在运行GRUNT时会出错

我确实试着通过提交一个编辑以供审查来将其添加到答案中。但它两次被全知全能的高级mods拒绝。。。事实上,这是一个有效的输入,并改进了给出的答案。注意
[]
cwd
src
的变化

files: [{
    expand: true,
    cwd: 'javascript/bills/',
    src: ['*.js'],
    dest: 'test/',
    ext: '.min.js',
    extDot: 'first'
}],

您可以使用grunt contrib uglify的banner属性来附加内容。

以下是grunt配置:

grunt.initConfig({
丑陋的:{
选项:{
横幅:grunt.file.read('./javascript/account/custom.js'),
美化:对,,
mangle:错,
压缩:错,
评论:“全部”
},
档案:{
是的,
cwd:'javascript/',
src:['bills/*.js'],
dest:'测试/',
分机:'.min.js',
extDot:“第一”
},
}

});谢谢-效果很好。我搜索了这些文档,试图找到一种在横幅中包含多个文件的方法,例如:
banner:grunt.file.read([./javascript/account/custom.js',./javascript/account-2/custom.js]),
但这不起作用。通过在多个文件上使用concat,然后在横幅中包含concat文件,找到了上述注释的解决方法