Reputation: 28488
My aim is to use the new DefinePlugin.runtimeValue() feature to conditionally define 'typeof window' to 'undefined' in the worker and 'object' outside the worker (web target)
currently, my unsatisfying code is:
new webpack.DefinePlugin({
'typeof window': webpack.DefinePlugin.runtimeValue(function({ module }) {
const isWorker = module.nameForCondition && /\.worker\./.test(module.nameForCondition());
return JSON.stringify(isWorker ? 'undefined' : 'object');
})
}),
and I wondering if I can detect worker-loader through the module object.
Upvotes: 1
Views: 100
Reputation: 28488
sorry for the noise, I found the answer by myself:
const isWorker = module.parser.state.compilation.compiler.name === 'worker';
Upvotes: 1