Socket
Socket
Sign inDemoInstall

babel-plugin-transform-require-stub

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-transform-require-stub

stub the required file by extension type


Version published
Weekly downloads
11
decreased by-59.26%
Maintainers
1
Weekly downloads
 
Created
Source

babel-plugin-transform-require-stub

Started as a fork of babel-plugin-transform-require-ignore

Ever wanted to test Webpacked frontend code... without webpack?

Well this lets you do just that, by stubbing out required files with specified extensions in your code, to achieve creating stubs where a webpack loader would be called.

Installation

  npm install --save-dev babel-plugin-transform-require-stub

Usage

Add the plugin to your .babelrc or package.json with a config like so:

{
  "plugins": [
    [
      "babel-plugin-transform-require-stub",
      {
        "extensions": [
          ".png", ".sass", ".styl"
        ],
        // this is used if there is no ".ext" property on the options object
        "defaultStub": {
          // replaces with the require path with the path supplied here to a stub, so require("./style$SOME_EXT_DEFINED_ABOVE") becomes require("$ABSOLUTE_PATH_TO_FILE")
          "file": "./fileToStub"
        },
        ".sass": {
          // replaces the require call with just the path string, so `require("./style.sass")` becomes just `"./style.sass"`
          "path": true
        },
        ".styl": {
          // value can be any valid json (string literal, number literal, boolean literal, null literal, object literal, or array literal)
          // the value is then inserted into the code where the require call is matched
          // eg require('styles.styl') would become { something: "here" }
          "value": {
            "something": "here"
          }
        }
      }
    ]
  ]
}

License

MIT

Keywords

FAQs

Package last updated on 21 May 2017

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc