nested-require-loader
v0.2.1
Published
Simply a nested require loader for webpack
Downloads
8
Readme
nested-require-loader
Simply resolves any require calls nested in a file using webpack.
$ npm install --save-dev nested-require-loader
Usage
In your webpack config:
module: {
rules: [
{
test: /manifest.json$/,
use: ['file-loader?name=manifest.json', 'nested-require-loader']
}
]
}
Note that this example also uses file-loader.
For example load a Web App Manifest through require in your application code:
require('./manifest.json');
With each internal resource requested through require rather than just a plain path:
{
"name": "Hello World",
...
"splash_screens": [
{
"src": "require('./images/splash-hi.png')",
"sizes": "2560x1440",
"type": "image/png"
},
...
],
"icons": [
{
"src": "require('./images/icon-hi.png')",
"sizes": "512x512",
"type": "image/png"
},
...
]
}
Options
Additional options may be applied to loader. If incorrect is specified, loader will throw an error.
|Option|Type|Default value|Description|
|---|---|---:|---|
|rawString
|Boolean|false|Ensures that no extra quotes are added if the type of returned value is a string |
Setting loader options
Object
module: {
rules: [
{
test: /.ext$/,
use: [
'other-loaders',
{
loader: 'nested-require-loader',
options: {
rawString: false
}
}
]
}
]
}
Inline
module: {
rules: [
{
test: /.ext$/,
use: ['other-loaders', 'nested-require-loader?rawString=false']
}
]
}