New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

generic-jsx-loader

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

generic-jsx-loader

A webpack loader for loading custom JSX

latest
Source
npmnpm
Version
0.9.8
Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

generic-jsx-loader npm version Build Status

A webpack loader for custom JSX. Can be used to represent custom data as raw XML inside JavaScript code.

This is a simple wrapper for generic-jsx-tranpiler npm package

How can this be used?

This can be used to use JSX to turn XML inside JavaScript into any type of data. For example React transforms JSX into raw JavaScript function calls React.createElement function calls (React Without JSX). This package can be used to easily transform raw XML in JavaScript (JSX) into custom data such as custom function calls, JSON, or other JS code/data.

Setup

npm install generic-jsx-transpiler

Usage

In your own JSX webpack loader

Writing a Loader

I have created a HyperScript loader

import genericJsxloader from 'generic-jsx-loader'

function serialize(component) {
    // This is where you can do custom transformations on the JSX
    //      'component' is a JS object with information on parsed XML
    // This function should return a string containing valid javascript code
    return "'JSX_REPLACEMENT'";
}

export default function loader(source) {
    const options = {
        serialize,
        // All options are passed to generic-jsx-transpiler
        //      new Parser({ serializer: options });
    };
    
    return genericJsxLoader(source, options);
}

In a single project

To use this generic loader in a single project add it to webpack.config.js:

module.exports = {
    ...
    module: {
        rules: [
            {
                test: /\.gjsx$/, //Replace this with any file extension including .js
                loader: 'jsx-hyperscript-loader',
                options: {
                    serialize: function(component) {
                        return "'JSX_REPLACEMENT'[";
                    }
                }
            }
        ]
    }
}

Keywords

react

FAQs

Package last updated on 09 Jan 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