-
Notifications
You must be signed in to change notification settings - Fork 421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
React Integration - the build doesn't include web component files #1396
Comments
Hi, I manage to ship a StencilJS component and a react wrapper The component is a Here is the live demo: The code is here 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 "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 |
Hi, thank you for your comment! |
@andresgutgon is there anything you believe we can improve in our docs to be more clear on shipping StencilJS components with React wrappers? |
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 |
I used the instruction provided on the website https://stenciljs.com/docs/react to integrate Stencil components into the React application.
The bundle with React components exists, it can be used, the
dev
task of the consumer react application works well.However, after running the
build
task, the individual web component files are not included thus web components are not being loaded as seen on the screen below:I switched to a create-react-app with the default configuration and there everything works fine.
Could you propose a solution for a React app built with vite that would include the web components?
A short discord discussion where I discussed this problem: https://discord.com/channels/520266681499779082/1107707233153855559/threads/1225105815208202330
The text was updated successfully, but these errors were encountered: