Open Nicktho opened 7 years ago
+1
Could you try with an explicit ident
so the {Function}
references are kept
{
test: /\.js$/,
use: [
{
loader: 'transform-loader',
options: {
ident: 'transform' // value (name) doesn't matter
transforms: [
staticify(staticifyConfig)
]
}
]
}
}
https://webpack.js.org/api/loaders/#this-query
If the loader was configured with an
options
object, this will point to that object. If the loader has no options, but was invoked with a query string, this will be a string starting with ?.
If options
set, it just run as next(this.options.transforms['transforms']);
in Webpack 3.
Any chance of this to be fixed after one year? If I understand right, this means that using a function as a transform is impossible in Webpack 3. No one is needing it? Or is it fixed in Webpack 4?
Possibly outdated by this point -- also I have do not have the surrounding context to explore this further in webpack 4, but my OP explained that you could get around this with webpack.LoaderOptionsPlugin
and plugins
Using webpack 4 and seems there's no way to use local transform functions.
I managed to get the correct transform index by using:
{
loader: "transform-loader?0",
options: {
'0': true,
transforms: [
function moduleBrfs(resource) {
return brfs(resource, {
parserOpts: {
sourceType: 'module'
}
})
}
]
}
}
But it fails because this.options in this line is undefined. This behavior occurs because when options is defined, it becomes this.query and this.options is removed
According to https://github.com/webpack-contrib/transform-loader/issues/20 passing transforms in
options
within the rule works, but it was throwing this for me:That was with this:
I had to revert to using
webpack.LoaderOptionsPlugin
and theplugins
part of my configuration for it to work.