I need to load a JS file as a string so I can run some analysis on it. I am trying to use raw-loader with Webpack (2.2.0).
I get: Cannot find module 'raw-loader!../
I've tried (yes, the path is correct):
let app = require('raw-loader!../../app.js').default;
let app = require('!!raw-loader!../../app.js').default;
I've even tried it without inline. Raw-loader doesn't get engaged, it just tried to load the JS file normally:
module.exports = {
module: {
rules: [
{
test: /\app.js$/i,
use: 'raw-loader',
loader: 'raw-loader',
}
]
}
}
raw-loader is in my package.json for the project. It is present in my node modules. I've blown-away my node_modules and have reinstalled. I've looked at many solutions and nothing seems to point to a fix.
You have an error in your regexp pattern.
You are using \a
which matches the bell character (ASCII 7)
And .
matches any character, you need to escape it.
Moreover, using both use
and loader
is misleading. You should use only one - see this answer:
When do I use 'use' and 'loader' in Webpack 2 module.rules?
Try to use:
module.exports = {
module: {
rules: [
{
test: /app\.js$/i,
loader: 'raw-loader'
}
]
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With