【问题标题】:Multiple destination directories using Uglify使用 Uglify 的多个目标目录
【发布时间】:2015-01-13 05:27:30
【问题描述】:

如果我有以下文件/目录结构:

somemodule/
└── amd
└── src
    └── foo.js
someothermodule/
└── amd
└── src
    └── bar.js

我能否让 grunt-contrib-uglify 产生以下缩小的输出?

somemodule/
└── amd
└── build
    └── foo.min.js
└── src
    └── foo.js
someothermodule/
└── amd
└── build
    └── bar.min.js
└── src
    └── bar.js

到目前为止,我已经尝试了以下 Grunt 配置:

grunt.initConfig({
    uglify: {
        dynamic_mappings: {
            files: [
                {
                    expand: true,
                    src: ['**/amd/src/*.js', '!**/node_modules/**'],
                    dest: 'build/',
                    ext: '.min.js',
                    extDot: 'first'
                },
            ],
        }
    }
});

这给了我一些东西,但不是我想要的(输出放在我项目根目录中的 build/ 目录中):

build/
├── somemodule
│   └── amd
│       └── src
│           └── foo.min.js
└── someothermodule
    └── amd
        └── src
            └── bar.min.js

从这里到哪里我有点卡住了 - 任何指针都将不胜感激。如果需要,非常乐意详细说明任何事情。

-戴夫

【问题讨论】:

    标签: gruntjs uglifyjs grunt-contrib-uglify


    【解决方案1】:

    根据这个 SO 问题设法找出我想做什么:How to grunt-uglify multiple script files while keeping folder structure

    我总结了以下重命名功能:

    files: grunt.file.expandMapping(['**/amd/src/*.js', '!**/node_modules/**'], '', {
               rename: function(destBase, destPath) {
                   destPath = destPath.replace('src', 'build');
                   destPath = destPath.replace('.js', '.min.js');
                   return destPath;
               }
    })
    

    【讨论】:

      猜你喜欢
      • 2020-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-06
      • 2013-10-24
      • 1970-01-01
      相关资源
      最近更新 更多