Skip to content

Commit bcf5b1e

Browse files
authored
Mark "lit" dependency as external to optimize bundle size and avoid issues when mixing Lit dependencies (#551)
* Mark "lit" dependency as external to optimize bundle size The "lit" dependency is now marked as external, meaning it won't be bundled with the library. This improves code reuse if another library that uses chameleon also uses Lit, and can also fix some issues as it won't mix Lit versions for the development server (because Chameleon was bundling Lit in prod mode, but another libraries use Lit in "dev" mode for the dev server). * Fix test runner not working * Use minor versions for the "lit" peerDependency
1 parent 360d0cf commit bcf5b1e

File tree

9 files changed

+42
-12
lines changed

9 files changed

+42
-12
lines changed

package-lock.json

Lines changed: 11 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
"@genexus/markdown-parser": "~0.3.0",
4343
"@open-wc/lit-helpers": "0.7.0",
4444
"html5-qrcode": "^2.3.8",
45-
"lit": "~3.3.0",
4645
"livekit-client": "~2.12.0",
4746
"mdast-util-from-markdown": "2.0.2",
4847
"monaco-editor": "^0.48.0",
@@ -78,6 +77,9 @@
7877
"typescript": "~5.4.5",
7978
"vite": "^5.2.10"
8079
},
80+
"peerDependencies": {
81+
"lit": "^3.3.0"
82+
},
8183
"husky": {
8284
"hooks": {
8385
"pre-commit": "lint-staged"

src/components/chat/internal/renders/actions.lit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { html } from "lit";
2-
import { when } from "lit/directives/when";
2+
import { when } from "lit/directives/when.js";
33

44
import { tokenMap } from "../../../../common/utils";
55
import type { ChatActionsRender, ChatMessage } from "../../types";

src/components/chat/internal/renders/code-block.lit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { html } from "lit";
2-
import { when } from "lit/directives/when";
2+
import { when } from "lit/directives/when.js";
33
import type { MarkdownViewerCodeRenderOptions } from "../../../markdown-viewer/parsers/types";
44
import type { ChatCallbacks, ChatCodeBlockRender } from "../../types";
55
import { copy } from "../../utils";

src/components/chat/internal/renders/content.lit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { html } from "lit";
2-
import { when } from "lit/directives/when";
2+
import { when } from "lit/directives/when.js";
33
import { tokenMap } from "../../../../common/utils";
44
import type {
55
ChatCodeBlockRender,

src/components/chat/internal/renders/file.lit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { html } from "lit";
2-
import { ifDefined } from "lit/directives/if-defined";
3-
import { when } from "lit/directives/when";
2+
import { ifDefined } from "lit/directives/if-defined.js";
3+
import { when } from "lit/directives/when.js";
44

55
import type { ChMimeTypeFormatMap } from "../../../../common/mimeTypes/mime-types";
66
import { tokenMap } from "../../../../common/utils";

src/components/chat/internal/renders/source.lit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { html } from "lit";
2-
import { when } from "lit/directives/when";
2+
import { when } from "lit/directives/when.js";
33
import { tokenMap } from "../../../../common/utils";
44
import type { ChatMessageSource, ChatSourceRender } from "../../types";
55

src/components/markdown-viewer/parsers/renders.lit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { html, nothing, type TemplateResult } from "lit";
2-
import { classMap } from "lit/directives/class-map";
2+
import { classMap } from "lit/directives/class-map.js";
33
import { AlignType, Table } from "mdast";
44
import { getLinkDefinition, setLinkDefinition } from "./link-resolver";
55
import type { rawHTMLToJSX } from "./raw-html-to-jsx.lit";

stencil.config.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { Config } from "@stencil/core";
22
import { OutputTarget } from "@stencil/core/internal";
3-
import { sass } from "@stencil/sass";
43
import { reactOutputTarget } from "@stencil/react-output-target";
4+
import { sass } from "@stencil/sass";
55

66
import { reactOutputExcludedComponents } from "./src/framework-integrations.ts";
77

8+
const isTesting = process.env.npm_lifecycle_script?.startsWith("stencil test");
9+
810
const outputTargets: OutputTarget[] = [
911
{
1012
type: "dist",
@@ -47,6 +49,24 @@ export const config: Config = {
4749
// library's components.
4850
enableImportInjection: true
4951
},
52+
53+
// Don't apply external dependencies when running test, because Stencil won't
54+
// be able resolve the imports
55+
rollupPlugins: {
56+
before: isTesting
57+
? []
58+
: [
59+
{
60+
name: "external-deps",
61+
options(options) {
62+
return {
63+
...options,
64+
external: [/^lit\/.*/]
65+
};
66+
}
67+
}
68+
]
69+
},
5070
testing: {
5171
browserArgs: ["--no-sandbox", "--disable-setuid-sandbox"],
5272
verbose: true,

0 commit comments

Comments
 (0)