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:
Will be loaded as:
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:
;
// webpack.config.jsmoduleexports = module: rules: test: /config\.json$/ use: loader: 'json-glob-loader' options: baseDir: path
config
- baseDir: baseDir from where glob will be applied (omitted from the resultant JSON declaration).
- transformStringsToArray: if set to true, will replace strings outside Arrays, transforming this into Arrays (optional, false by default).
- globOptions: glob options to be applied on the glob method.
KNOWN ISSUES
🙋 If no matches are found using a legit expression, then no replacement will be made; or any string would disappear. ** Make sure there is at least one file on your folders... **
testing
$ npm test