I'm trying to write a Webpack loader that whenever I import a specific fixed string "Hello" like below, it runs my loader at compile time and return a non-cacheable string.
import x from 'Hello';
console.log(x)
The thing here is that "Hello" is not a file.
I was trying to do this by introducing my loader in the Webpack Config in module.rules
by having my loader's test
prop as "Hello" but it didn't work.
// webpack.config.js
{
...
module: {
rules: [
{
test: /Hello/,
use: [
{
loader: path.resolve('./my-custom-loader.js'),
options: {
/* ... */
},
},
],
},
...
],
...
}
}
Is this even possible in Webpack?