New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

json-glob-loader

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-glob-loader

webpack JSON loader which will search and resolve file paths expressed using glob patterns.

latest
Source
npmnpm
Version
0.2.1
Version published
Weekly downloads
8
100%
Maintainers
1
Weekly downloads
 
Created
Source

npm Build Status

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';
// webpack.config.js
module.exports = {
  module: {
    rules: [
      {
        test: /config\.json$/,
        use: [{
          loader: 'json-glob-loader',
          options: {
            baseDir: path.join(__dirname, 'my-files-dir/'),
          }
        }]
      }
    ]
  }
}

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
    

    License

    MIT

Keywords

webpack

FAQs

Package last updated on 27 Oct 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts