@financial-times/x-node-jsx

14.7.7 • Public • Published

x-node-jsx

This module extends Node's require() function to enable the use of .jsx files at runtime. It uses Pirates to safely add a require hook and Sucrase to transform code on-the-fly.

Installation

This module is supported on Node 12 and is distributed on npm.

npm install -S @financial-times/x-node-jsx

To add the require hook you only need to import the register module. You can do this programmatically in your application code:

require('@financial-times/x-node-jsx/register');

Or use the --require or -r flag when invoking Node:

node --require "@financial-times/x-node-jsx/register"

You can also add the require hook manually. This will return a function which can be used to later remove the hook:

const addHook = require('@financial-times/x-node-jsx');

const removeHook = addHook();

// Some time later...
removeHook();

An options object may also be provided, the options and their defaults are shown below:

const addHook = require('@financial-times/x-node-jsx');

addHook({
	production: true,
	transforms: ['imports', 'jsx']
});

These options will be passed to the Sucrase module. To see more options take a look at the Sucrase documentation.

After the hook has been added .jsx files can be imported and will be transformed on-the-fly:

// Add the hook
require('@financial-times/x-node-jsx/register');

// Transparently require .jsx files
const App = require('./components/App.jsx');

Readme

Keywords

Package Sidebar

Install

npm i @financial-times/x-node-jsx

Weekly Downloads

189

Version

14.7.7

License

ISC

Unpacked Size

3.19 kB

Total Files

4

Last publish

Collaborators

  • robgodfrey
  • robertboulton
  • seraph2000
  • hamza.samih
  • notlee
  • emmalewis
  • aendra
  • the-ft
  • rowanmanning
  • chee
  • alexwilson