Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

Trying to override css and js blockReplacements - not working? #471

Closed
trludewig opened this issue Oct 28, 2014 · 4 comments
Closed

Trying to override css and js blockReplacements - not working? #471

trludewig opened this issue Oct 28, 2014 · 4 comments

Comments

@trludewig
Copy link

I am guessing this is user error on my part. But could someone take a look at this? I want to replace the css and js includes with custom text, not the out-of-the-box. Here is a snippet from my Grunt file.

   useminPrepare: {
        html: ['<%= appConfig.dist %>/{,*/}*.html', '<%= appConfig.dist %>/{,*/}*.page'],
        options: {}
    },

    // Performs rewrites based on filerev and the useminPrepare configuration
    usemin: {
        html: ['<%= appConfig.dist %>/{,*/}*.html', '<%= appConfig.dist %>/{,*/}*.page'],
        options: {
            blockReplacements: {
                css: function (block) {
                    grunt.log.writeln('in css block!');
                    return '<link href="{!URLFOR($Resource.SCSClientView, \'' + block.dest + '\')}" type="text/css" rel="stylesheet" />';
                },
                js: function(block) {
                    grunt.log.writeln('in js block!');
                    return '<script type="text/javascript" src="{!URLFOR($Resource.SCSClientView, \'' + block.dest + '\')}"></script>';
                }
            }
        }
    }

In addition, I also tried modifying the following in fileprocessor.js

var defaultBlockReplacements = {
css: function (block) {
var media = block.media ? ' media="' + block.media + '"' : '';
return '<link rel="stylesheet" href="' + block.dest + '"' + media + '>';
// I tried returning something else here. It didn't get picked up or even called, it seems.

},
js: function (block) {
var defer = block.defer ? 'defer ' : '';
var async = block.async ? 'async ' : '';
return '<script ' + defer + async + 'src="' + block.dest + '"></script>';
// I tried returning something else here. It didn't get picked up or even called, it seems.

}
};

@stephanebachelier
Copy link
Collaborator

@trludewig Have you tried to use the workaround proposed in #444.

@trludewig
Copy link
Author

Hmm, I'm not using filerev. I'm not sure why what I was trying doesn't work. I'll look at 444. Thanks.

@trludewig
Copy link
Author

This works after all.

@stalsma
Copy link

stalsma commented Apr 15, 2016

Just to add on to this for future visitors, the blockReplacements does not exist in early versions of useMin. I had to upgrade my package; then it worked w/o issue.

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

No branches or pull requests

3 participants