New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-transform-import-to-read-file-sync

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-import-to-read-file-sync

Use import to read any file contents to local variable in Node.js. Filename is resolved like regular import source.

  • 0.2.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

babel-plugin-transform-import-to-read-file-sync

Use import to read any file contents to local variable in Node.js. Filename is resolved like regular import source.

Example

import file from "./file.txt";
// => const file = _readFileSync(require.resolve('./file.txt'), "utf8");
// readFileSync is imported from 'fs' as some unique identifier, if not already available.

console.log(require("./file.txt"));
// => console.log(require('fs').readFileSync(require.resolve('./file.txt'), "utf8"));
.babelrc
{
  "plugins": [
    [
      "transform-import-to-read-file-sync",
      {
        "test": "\\.txt$",
        "options": "utf8"
      }
    ]
  ]
}

Options

Plugin expects options object. test property is pattern to match files. options property is passed directly to readFileSync as second argument. If no options is specified, then readFileSync returns a buffer.

You can use "options" array property to specify multiple test patterns and readFileSync options:

{
  "plugins": [
    [
      "transform-import-to-read-file-sync",
      {
        "options": [
          {
            "test": "\\.txt$",
            "options": "utf8"
          },
          {
            "test": "\\.png$"
          }
        ]
      }
    ]
  ]
}

Keywords

FAQs

Package last updated on 08 Jul 2019

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