【问题标题】:Create subtasks that override `options` but use task level `src`创建覆盖`options`但使用任务级别`src`的子任务
【发布时间】:2017-04-27 18:22:13
【问题描述】:

到目前为止我的 gruntfile

uglify: {
    src: [
        ...
    ],
    dest: 'js/application.min.js',
    options: {
        'compress': {},
        'reserveDOMCache': true,
        'enclose': undefined,
        'exportAll': false,
        'expression': false,
        'preserveComments': false,
        'report': 'min',
        'sourceMap': false,
        'sourceMapIn': undefined,
        'sourceMapIncludeSources': false,
        'sourceMapName': undefined,
        'wrap': undefined
    },
    development: {
        options: {
            'beautify': false,
            'mangle': true
        }
    },
    production: {
        options: {
            'beautify': true,
            'mangle': false
        }
    }
}

但是,当我运行任务 uglify:development 时,它会回复 No files created.

【问题讨论】:

    标签: gruntjs grunt-contrib-uglify


    【解决方案1】:

    据我所知,这是不可能的。您需要为每个目标显式定义一个 src。

    您可以在配置之外声明一个变量并将其添加到每个目标:

    var mySources = ['file1.txt', 'file2.txt']; //declared outside config
    
     development: {
         src: mySources, //add variable to each target
    

    或者你可以在配置中声明一个变量:

    mySourcesInside: ['file1.txt'], //declared within config
    
      development: {
           src: '<%= mySourcesInside%>', //reference variable in each target
    

    或者,您可以使用 grunt-override-config https://github.com/masakura/grunt-override-config 之类的东西并只声明一个 uglify 目标并覆盖选项。

    【讨论】:

    • 我能够调整您的解决方案以按照我想要的方式使用 src: '&lt;%= uglify.src%&gt;'
    猜你喜欢
    • 1970-01-01
    • 2021-09-27
    • 1970-01-01
    • 1970-01-01
    • 2017-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多