The issue with passing functions to loaders in webpack2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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