Skip to content

Allows imports with the "!text" suffix to be imported as a string in Node.

License

Notifications You must be signed in to change notification settings

onlywei/babel-plugin-transform-import-bangtext-node

Repository files navigation

Build Status

babel-plugin-transform-import-bangtext-node

Transforms:

import foo from './foo!text';

into

var foo = require('fs').readFileSync('./foo', 'utf8');

Installation

npm install --save-dev babel-plugin-transform-import-bangtext-node

Usage

This only works in Node environments. Do not try to use this plugin in a browser environment.

require('babel-register')({
  plugins: [
    ['transform-import-bangtext-node', {basePath: '/path/to/wherever'}]
  ]
});

Options

  • basePath - When importing anything that does not begin with /, ./, or ../, this option can be set to join with the path using path.join(basePath, target). Using an absolute base path is recommended.

  • encoding - The encoding option passed to fs.readFileSync(). Defaults to utf8.

Why does this plugin exist?

The functionality of this plugin is intended to mirror the SystemJS text plugin that is used in a browser environment. Using this transform will allow you to import modules written with the SystemJS text plugin into your Node environment.

About

Allows imports with the "!text" suffix to be imported as a string in Node.

Resources

License

Stars

Watchers

Forks

Packages

No packages published