Socket
Socket
Sign inDemoInstall

babel-plugin-include

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    babel-plugin-include

Includes a file as a string literal


Version published
Weekly downloads
34
increased by112.5%
Maintainers
1
Install size
6.65 kB
Created
Weekly downloads
 

Readme

Source

babel-plugin-include

Adds an include function which places the given file into a string at compile-time.

Installation

$ npm install babel-plugin-include

Usage

.babelrc

{
  "plugins": ["include"]
}

Via CLI

$ babel --plugins include script.js

Via Node API

require('babel').transform('code', {
  plugins: ['include']
});

Example

Given text.txt with the contents:

Hello, World!

the following JS:

let file = include("text.txt");

will be compiled to:

let file = "Hello, World!";

Information

  • The file is included relative to the JS file the include is in unless a root is specified in the plugin options, in which case, the root is used. (See below for info on root)
  • The default encoding is utf8 however that can be changed
  • Special characters/unprintables are automatically escaped
  • The include function takes a single string as argument. Any following arguments are ignored.

Options

babel-plugin-include allows you to change various settings by providing an options object by using the following instead:

{
    plugins: [
        ['include', { options }]
    ]
}

where { options } is the options object. The following options are available:

root

The root option specifies the root in which files are included from. e.g.:

{
    plugins: [
        ['include', {
            'root': 'proj/src'
        }]
    ]
}

encoding

The encoding option specifies which encoding to use when including files. Default is utf8

{
    plugins: [
        ['include', {
            'encoding': 'ucs2'
        }]
    ]
}

normalizeNewline

The normalize newline option specifies whether newlines should be normalized or not. This converts \r\n to \n and removes and trailing newlines. Disable this for binary files or other applicable locations.

{
    plugins: [
        ['include', {
            'encoding': 'ucs2'
        }]
    ]
}

FAQs

Last updated on 28 Oct 2016

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc