简体   繁体   中英

grunt-usemin with pattern is only replacing the first match

I have the following in my gruntfile:

usemin: {
    html: ['<%= yeoman.dist %>/**/*.html'],
    css: ['<%= yeoman.dist %>/styles/**/*.css'],
    js: ['<%= yeoman.dist %>/scripts/**/*.js'],
    options: {
        assetsDirs: ['<%= yeoman.dist %>','<%= yeoman.dist %>/styles/**/*'],
        patterns: {
            js: [
                [/css:["']styles\/?.*\/(.*\.css)['"]/g, 'revved css resolves']
            ]
        }
    }
}

Which does what I want, given a javascript file with a reference to a revved css file, it replaces the occurrence. But only the first occurrence. I need this to work globally (hence the '/g' modifier. Any clues?

The input is a file that looks roughly like:

foo:{includes:{css:"styles/something.css"}},bar:{includes:{css:"styles/something.css"}}

What I end up with is (assuming 0123456 is the hash from rev):

foo:{includes:{css:"styles/0123456.something.css"}},bar:{includes:{css:"styles/something.css"}}

What I want is:

foo:{includes:{css:"styles/0123456.something.css"}},bar:{includes:{css:"styles/0123456.something.css"}}

Thanks.

我的正则表达式太贪心了,我通过用/ /css:"styles\\/?[A-Za-z]*\\/+([A-Za-z0-9]+\\.css)"}/g替换我的模式来解决此问题: /css:"styles\\/?[A-Za-z]*\\/+([A-Za-z0-9]+\\.css)"}/g ,现在我恢复了业务。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM