Skip to content

Instantly share code, notes, and snippets.

@jescalan
Created February 9, 2017 20:16
Show Gist options
  • Save jescalan/da985d3b26d9f02db271aea99b080315 to your computer and use it in GitHub Desktop.
Save jescalan/da985d3b26d9f02db271aea99b080315 to your computer and use it in GitHub Desktop.
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