首页 > Grunt text replace 如何保持目录结构

Grunt text replace 如何保持目录结构

假设有这样的目录结构

── view
    ├── a
    │   └── a.php
    └── b.php

Gruntfile.js:

module.exports = function(grunt) {

    grunt.initConfig({
        replace: {
            files: {
                replacements: [{
                    from: '.js',
                    to: '.js?v=1'
                }],
                expand: true,
                cwd: 'view/',
                src: ['**/*.php', '*.php'],
                dest: 'dist/'
            }
        }

    });

    grunt.loadNpmTasks('grunt-text-replace');

    grunt.registerTask('default', ['replace']);

};

然后我得到这样的目录

── dist
    ├── a.php
    └── b.php

请问是我哪里写错了吗?


貌似这个插件不支持这样做,换了 grunt-replace 以后可以了

module.exports = function(grunt) {

    grunt.initConfig({
        replace: {
            dist: {
                options: {
                    patterns: [{
                        match: /js/g,
                        replacement: 'js?v=1'
                    }]
                },
                files: [{
                    expand: true,
                    cwd: 'view/',
                    src: ['**/*.php'],
                    dest: 'build/'
                }]
            }
        }
    });


    grunt.loadNpmTasks('grunt-replace');

    grunt.registerTask('default', ['replace']);

};

【热门文章】
【热门文章】