Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overwrite option not working? #37

Open
ryexley opened this issue Mar 10, 2015 · 4 comments
Open

Overwrite option not working? #37

ryexley opened this issue Mar 10, 2015 · 4 comments

Comments

@ryexley
Copy link

ryexley commented Mar 10, 2015

I have the following configuration:

"style-image-refs": {
    src: ["app/assets/stylesheets/**/*.css"],
    overwrite: true,
    replacements: [
        { from: "url(\"/images/", to: "url(\"/assets/" },
        { from: "url(\"../images/", to: "url(\"/assets/" }
    ]
}

to replace image URL paths in CSS files. The overwrite attribute seems to be causing the replace functionality to break. If I modify the configuration to write the target files to a different directory, like this:

"style-image-refs": {
    src: ["app/assets/stylesheets/**/*.css"],
    dest: "app/assets/stylesheets/fixed/",
    replacements: [
        { from: "url(\"/images/", to: "url(\"/assets/" },
        { from: "url(\"../images/", to: "url(\"/assets/" }
    ]
}

the files get written to the fixed directory, and the target strings are replaced as expected. But when I use the overwrite attribute it doesn't work.

Anyone else experiencing this? Is my configuration setup wrong or something? Any help would be greatly appreciated.

Thanks.

@ryexley
Copy link
Author

ryexley commented Mar 10, 2015

I'm pretty sure I can confirm this by looking at the source. The only place the overwrite option is referenced is in the replace function, and in the errorMessages object. It appears to be checked in the replace function, but it never actually gets passed on to the replaceFileMultiple function...so it doesn't appear to be getting used at all. Am I missing something?

@okcompewter
Copy link

Same here, the overwrite: true option gives an error:
Warning: Cannot read property 'slice' of undefined� Use --force to continue.

@ra-ryan
Copy link

ra-ryan commented Aug 27, 2015

@ryexley @okcompewter you've probably moved on by now but I figured I would share my results anyways. You can overwrite the target files by only including the src attribute and leaving out both the dest and overwrite attributes. This isn't how it is documented but it worked for me. So your original code sample would look like this:

"style-image-refs": {
    src: ["app/assets/stylesheets/**/*.css"],
    replacements: [
        { from: "url(\"/images/", to: "url(\"/assets/" },
        { from: "url(\"../images/", to: "url(\"/assets/" }
    ]
}

@Mifrill
Copy link

Mifrill commented May 20, 2017

Use grunt-string-replace

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants