jamesandersen / string-replace-webpack-plugin

Replace string tokens in a bundle.
93 stars 27 forks source link

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

Closed mdreizin closed 9 years ago

mdreizin commented 9 years ago

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 commented 9 years ago

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

jamesandersen commented 9 years ago

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