-
Notifications
You must be signed in to change notification settings - Fork 12
Description
When using a function in params, it is not defined for the first time that file is processed, however, on subsequent run (such as the second time using webpack watch), it is defined correctly.
We use the 'thread-loader', and removing that does seem to make this work fine.
However, with it enabled, the first time the file is processed, it produces and error.
I can tell it works on subsequent processing with "watch" because putting a console.log in the function prints to console.
The error is:
includeID is not defined
at eval (eval at ifComparator (node_modules\webpack-preprocessor-loader\dist\filter.js:134:24), <anonymous>:3:1)
As far as I can tell, this is only the case for functions, and normal values are perfectly fine.
So, for example, we have this:
const Config = {
units: ["Foo", "Baz"]
}
...
{
loader: 'webpack-preprocessor-loader',
options: {
params: {
includeID: function(id: string) {
return Config.units.includes(id);
}
}
}
And then the file looks like this:
// #!if includeID("Foo")
import {} from 'units/Foo';
// #!endif
// #!if includeID("Bar")
import {} from 'units/Bar';
// #!endif
// #!if includeID("Baz")
import {} from 'units/Baz';
// #!endif
Some other things which might affect it:
The webpack config is done in TS not JS.
We use 'thread-loader', and removing that works.