Closed mstijak closed 8 years ago
@mstijak does this even work with React?
@trueadm
Let me explain how this works. In my app I have a large number of components. Each component uses JSX in the render method and that gets translated into React.createElement
or Inferno.createBlueprint
calls. Switching from React to Inferno requires changing import statements on top of each component file, which is a real pain. React already supports pragma
option which allows you to replace React.createElement
calls with something else. In this pull request I added the same for Inferno and now it's possible to set that both target the same name.
["babel-plugin-inferno", { "pragma" : "Lib" }],
or
["babel-plugin-transform-react-jsx", { "pragma": "VDOM.createElement" }],
React.createElement -> Lib.createElement
React.Component -> Lib.Component
Inferno.createBlueprint -> Lib.createBlueprint
Inferno.Component -> Lib.Component
On top of each file
import Lib from './Lib'
//import React from 'react'; //not required anymore
//import Inferno from 'inferno'; //not required anymore
And Lib.js
export React as Lib from 'react';
//or
export Inferno as Lib from 'inferno';
// some details missing here
That's the general picture. Some details are missing.
If there is a better way I would be very glad to hear about it.
@mstijak makes sense! :) merged
cool feature :+1:
I find this helpful for switching between React or Inferno during development.