-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(output-target): add output target entries which do not auto defi…
…ne custom elements Since liquid v4.6.0 the includeDefineCustomElements option set to true. With the includeDefineCustomElements option set to true, you don't need to define the custom elements from liquid react yourself. The custom elements get registered with the Custom Elements Registry as soon as imported. We didn't see this as a breaking change, because calling the defineCustomElements helper method manually would not break anything, even if the elements were already defined. However, things get tricky, when bundling liquid components into another library: With the includeDefineCustomElements option set to true, the react.js and vue.js files within liquid import the defineCustomElements helper and execute it. The defineCustomElements helper imports the bootstrapLazy helper which in turn includes dynamic import statements for all components. Now, a bundler cannot know which component will be lazy loaded eventually, so it includes all components as chunks into the bundle. The app that consumes the library can load only what's needed, but the bundle is still unnecessary big, including all Liquid components, even if not used. In order to solve this issue, we add additional entry points to the output targets, which do not include the defineCustomElements helper utility. This allows to manually register custom elements on a as-needed basis, and fixes issues with the bundling, because dynamic imports are not used in the code. Resolves #700
- Loading branch information
1 parent
13a993f
commit 6077647
Showing
8 changed files
with
123 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const { readFile, writeFile } = require('fs').promises | ||
const outputTarget = process.argv[2] | ||
|
||
;(async () => { | ||
const data = await readFile(`./out/${outputTarget}.ts`, 'utf8') | ||
|
||
const defineIncluded = data | ||
.replace( | ||
"import type { JSX } from '../dist/components'", | ||
"import type { JSX } from '../dist/types/components'" | ||
) | ||
.replace( | ||
"import { defineCustomElements } from '../dist/components/dist/loader/index.js';", | ||
"import { defineCustomElements } from '../dist/loader/index.es2017.js';" | ||
) | ||
|
||
const defineExcluded = data | ||
.replace( | ||
"import type { JSX } from '../dist/components'", | ||
"import type { JSX } from '../dist/types/components'" | ||
) | ||
.split('\n') | ||
.filter((line) => !line.includes('defineCustomElements')) | ||
.join('\n') | ||
|
||
await Promise.all([ | ||
writeFile(`./out/${outputTarget}.ts`, defineIncluded, 'utf8'), | ||
writeFile( | ||
`./out/${outputTarget}-define-excluded.ts`, | ||
defineExcluded, | ||
'utf8' | ||
), | ||
]) | ||
})() |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6077647
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
liquid – ./
liquid-git-main-uxsd.vercel.app
liquid-oxygen.vercel.app
liquid-uxsd.vercel.app