Skip to content

preserve loader "this" context for "replacement" function#7

Closed
mdreizin wants to merge 3 commits intojamesandersen:masterfrom
mdreizin:master
Closed

preserve loader "this" context for "replacement" function#7
mdreizin wants to merge 3 commits intojamesandersen:masterfrom
mdreizin:master

Conversation

@mdreizin
Copy link

It helps to save loader this context during replacement. It is very useful in case when you need to have access to this context, for instance this.options:

{
    test: /\.shtml$/,
    loader: StringReplacePlugin.replace('html-loader', {
        replacements: [{
            pattern: /{{publicPath}}/gi,
            replacement: function () {
                return this.options.output.publicPath;
            }
        }]
    })
}

@jamesandersen
Copy link
Owner

Thanks for the contribution; this is a nice improvement. I appreciate the tests as well.

@jamesandersen
Copy link
Owner

I've rebased the branch and merged it in #8

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

Successfully merging this pull request may close these issues.

2 participants