Giter Club home page Giter Club logo

Comments (4)

andresgutgon avatar andresgutgon commented on June 20, 2024 1

Yes, I would do the example with Rollup as the build system for the React library. I think it is the most commonly used. And the react app using the react library I would do it with Vite. I think a bit the same, today is used a lot.

Oh, and I would differentiate the targets with one full example for each target. Why I would use one target and not the other? those explanations would be lovely. I know you have a targets section but wasn't clear enough for me. The examples would help.

Lastly in the react integration would be super nice to explain how is configured the package.json exports.

from stencil-site.

andresgutgon avatar andresgutgon commented on June 20, 2024

Hi, I manage to ship a StencilJS component and a react wrapper

The component is a iframe wrapper that syncs fields between the react app and the iframe

Here is the live demo:
https://latitude-embed.vercel.app/embedding

The code is here

  1. webcomponent
  2. react library
  3. React app using react library

This is the config

// ./packages/client/webcomponents/stencil.config.ts
import { Config } from '@stencil/core'
import { reactOutputTarget } from '@stencil/react-output-target'

// NOTE: `externalRuntime: false` why?
// Docs: https://stenciljs.com/docs/custom-elements#externalruntime
// This compile in this package `@stencil/core`. Other option would be
// to do it in `@latitude-data/react` by requiring as dependency `@stencil/core`
// But for now because we only have one component I think is fine to ship it here.
// so it has the runtime
export const config: Config = {
  namespace: 'webcomponents',
  outputTargets: [
    { type: 'docs-readme' },
    { type: 'dist' },
    {
      type: 'dist-custom-elements',
      customElementsExportBehavior: 'single-export-module',
      generateTypeDeclarations: true,
      externalRuntime: false,
    },
    reactOutputTarget({
      componentCorePackage: '@latitude-data/webcomponents',
      proxiesFile: '../react/src/webcomponents/index.ts',
      customElementsDir: 'dist/components',
      includeImportCustomElements: true,
    }),
  ],
  testing: {
    browserHeadless: 'new',
  },
}

And very important the config for packages/client/webcomponents/package.json

  "main": "./dist/index.cjs.js",
  "module": "./dist/index.js",
  "collection": "dist/collection/collection-manifest.json",
  "collection:main": "dist/collection/index.js",
  "unpkg": "dist/webcomponents/webcomponents.esm.js",
  "types": "./dist/components/index.d.ts",
  "exports": {
    "./dist/loader": {
      "import": "./dist/loader/index.js",
      "types": "./dist/loader/index.d.ts"
    },
    "./dist/components": {
      "import": "./dist/components/index.js",
      "types": "./dist/components/index.d.ts"
    },
    "./dist/components/latitude-embed.js": {
      "import": "./dist/components/latitude-embed.js",
      "types": "./dist/types/components.d.ts"
    }
  },
  "files": [
    "dist/"
  ],

I hope this can help

from stencil-site.

Kurzas avatar Kurzas commented on June 20, 2024

Hi, thank you for your comment!
I managed to make it work differently too, but I think the documentation should contain a working example so that it could be used as a reference for everyone :)

from stencil-site.

christian-bromann avatar christian-bromann commented on June 20, 2024

@andresgutgon is there anything you believe we can improve in our docs to be more clear on shipping StencilJS components with React wrappers?

from stencil-site.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.