Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
The issue with passing functions to loaders in webpack2
module.exports = function (source) {
console.log(this.query) // { foo: [null] } -- this is because when it's json serialized, it nulls out functions
const realOptions = this.options.module.rules.reduce((m, r) => {
const fooLoaderUse = r.use.find((u) => u.loader === 'foo-loader')
return fooLoaderUse ? fooLoaderUse.options : m
}, null)
console.log(realOptions) // foo: [() => 'bar'] -- it works, but is v. ugly
}
module.exports = {
module: {
rules: [
test: /\.foo$/,
use: [{ loader: 'foo-loader', options: { foo: [() => 'bar'] } }]
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment