0.6.5 • Published 3 years ago

lwc2react v0.6.5

Weekly downloads
16
License
MIT
Repository
-
Last release
3 years ago

lwc2react

A rollup plugin for compile-time conversion of lwc components to react for easy interop. This is a proof of concept and NOT ready for use in production!

What is working:

  1. Template data binding and reactive data
  2. Template lists
  3. Template conditionals
  4. Scoped CSS
  5. @api properties
  6. slots (named and anonymous)
  7. click events
  8. lifecycle methods

What is not working:

  1. Not all form/input events
  2. Custom events
  3. Wire adapters

Example

Add the lwc2react plugin. Make sure to configure it to process your lwc modules with the include option:

import lwc from '@lwc/rollup-plugin';
import resolve from 'rollup-plugin-node-resolve';
import replace from 'rollup-plugin-replace';
import commonjs from 'rollup-plugin-commonjs';
import path from 'path';
import lwc2react from 'lwc2react';

const outputDir = path.resolve(__dirname, `./src/dist`);
const input = path.resolve(__dirname, './src/index.js');
const output = path.join(outputDir, 'app.js');
const env = process.env.NODE_ENV || 'development';

export default {
  input,
  output: {
    format: 'iife',
    file: path.join(outputDir, 'app.js'),
  },
  plugins: [
    resolve(),
    lwc({
      rootDir: "./src",
      modules: [
        {
          dir: 'modules',
        },
      ],
    }),
    commonjs(),
    replace({'process.env.NODE_ENV': JSON.stringify(env)}),
    lwc2react({
      include: "**/modules/my/**"
    }),
  ],
};

Now any react component can render an LWC component:

import React from 'react';
import MyComp from 'my/comp'; // lwc component

export default function App() {
    return <div>
        <MyComp />
    </div>
}
0.6.3

3 years ago

0.6.2

3 years ago

0.6.5

3 years ago

0.6.4

3 years ago

0.5.0

3 years ago

0.6.1

3 years ago

0.6.0

3 years ago

0.4.0

3 years ago

0.3.0

3 years ago

0.2.0

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago