
json-glob-loader
A loader for webpack that analyzes any JSON searching for file paths using (glob)[https://www.npmjs.com/package/glob]'s patterns, so they will be replaced inside the JSON.
Assuming this file tree:
└── my-files-dir
├── a.foo
├── a2.foo
└── b.foo
This simple a JSON with this content:
{
"foo":true,
"files":[
"*"
],
"some-more": {
"data": [
"first",
"a*",
"last"
]
}
}
Will be loaded as:
{
"foo":true,
"files":[
"a.foo",
"a2.foo"
"b.foo"
],
"some-more": {
"data": [
"first",
"a.foo",
"a2.foo",
"last"
]
}
}
Getting Started
To begin, you'll need to install json-glob-loader:
$ npm install json-glob-loader --save-dev
Then add the loader to your webpack config. For example:
import myFile from '../wherever/my/json/is/config.js';
module.exports = {
module: {
rules: [
{
test: /config\.json$/,
use: [{
loader: 'json-glob-loader',
options: {
baseDir: path.join(__dirname, 'my-files-dir/'),
}
}]
}
]
}
}
config