-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(bundler): prevent vite bundling errors in downstream projects (#3349
) this commit adds experimental support for using stencil component libraries in projects that use bundlers such as vite. prior to this commit, stencil component libraries that were used in projects that used such bundlers would have issues lazily-loading components at runtime. this is due to restrictions the bundlers themselves place on the filepaths that can be used in dynamic import statements. this commit does not introduce the ability for stencil's compiler to use bundlers other than rollup under the hood. it only permits a compiled component library (that uses the `dist` output target) to be used in an application that uses a bundler built atop of rollup. due to the restrictions that rollup may impose on dynamic imports, this commit adds the ability to add an explicit `import()` statement for each lazily-loadable bundle. in order to keep the runtime small, this feature is hidden behind a new feature flag, `experimentalImportInjection` this pr build's atop the work done by @johnjenkins in #2959 and the test cases provided by @PrinceManfred in #2959 (comment). Without their contributions, this commit would not have been possible. add a stencil component library to be used in tests that verify applications that consume the library and are bundled with vite, parcel, etc. add an application that is built using vite to the bundler test directory. it consumes a small stencil library build using the `dist` output target, and verifies that the application can load the web component when the application has been built using vite. add infrastructure for running the bundler tests in karma. karma was chosen to align with existing parts of our technical stack (see the `test/karma` directory), and to expedite the initial implementation phase of these tests. karma can be difficult to configure, and even more difficult to add new (i.e. different) testing paradigms and testing strategies to. given that these tests do not use browserstack and are a significant departure from the existing karma tests, it felt 'ok' to split these off into a separate set of tests (with their own configuration). in order to get tests up and running, a utilities file, `test/bundler/karma-stencil-utils.ts` has been created. this file is largely based off of `test/karma/test-app/util.ts`. parts of the existing utility file were not ported over if they were deemed unnecessary, and attempts were made to clean up the existing code to improve their readability. wire the bundler tests to github actions. these tests are kept in a new reusable workflow that can run in parallel with existing analysis, unit and e2e tests STENCIL-339: Integrate Bundler Functionality
- Loading branch information
1 parent
d134830
commit 4c8d8c0
Showing
32 changed files
with
8,592 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Bundler Tests | ||
|
||
on: | ||
workflow_call: | ||
# Make this a reusable workflow, no value needed | ||
# https://docs.github.com/en/actions/using-workflows/reusing-workflows | ||
|
||
jobs: | ||
bundler_tests: | ||
name: Verify Bundlers | ||
runs-on: 'ubuntu-latest' | ||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # v2.4.0 | ||
|
||
- name: Get Core Dependencies | ||
uses: ./.github/workflows/actions/get-core-dependencies | ||
|
||
- name: Download Build Archive | ||
uses: ./.github/workflows/actions/download-archive | ||
with: | ||
name: stencil-core | ||
path: . | ||
filename: stencil-core-build.zip | ||
|
||
- name: Bundler Tests | ||
run: npm run test.bundlers | ||
shell: bash |
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
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,5 @@ | ||
dist/ | ||
loader/ | ||
www/ | ||
|
||
node_modules/ |
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,16 @@ | ||
# component-library | ||
|
||
This directory contains a small Stencil library to be consumed by other applications for testing purposes. | ||
|
||
The library consists of a single component, `<my-component></my-component>`. | ||
Documentation for using this component can be found in the [README.md file](./src/components/my-component/readme.md) for | ||
the component. | ||
|
||
## scripts | ||
|
||
This library contains three NPM scripts: | ||
|
||
- `build` - builds the project for use in other applications | ||
- `clean` - removes previously created build artifacts | ||
- `start` - starts up a local dev server to validate the component looks/behaves as expected (without having to | ||
consume it in an application) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "component-library", | ||
"version": "0.0.1", | ||
"description": "Stencil Component Starter", | ||
"main": "dist/index.cjs.js", | ||
"module": "dist/index.js", | ||
"es2015": "dist/esm/index.mjs", | ||
"es2017": "dist/esm/index.mjs", | ||
"types": "dist/types/index.d.ts", | ||
"collection": "dist/collection/collection-manifest.json", | ||
"collection:main": "dist/collection/index.js", | ||
"unpkg": "dist/component-library/component-library.esm.js", | ||
"files": [ | ||
"dist/", | ||
"loader/" | ||
], | ||
"scripts": { | ||
"build": "node ../../../bin/stencil build --docs", | ||
"clean": "rm -rf dist loader www", | ||
"start": "node ../../../bin/stencil build --dev --watch --serve" | ||
}, | ||
"license": "MIT" | ||
} |
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,61 @@ | ||
/* eslint-disable */ | ||
/* tslint:disable */ | ||
/** | ||
* This is an autogenerated file created by the Stencil compiler. | ||
* It contains typing information for all components that exist in this project. | ||
*/ | ||
import { HTMLStencilElement, JSXBase } from "@stencil/core/internal"; | ||
export namespace Components { | ||
interface MyComponent { | ||
/** | ||
* The first name | ||
*/ | ||
"first": string; | ||
/** | ||
* The last name | ||
*/ | ||
"last": string; | ||
/** | ||
* The middle name | ||
*/ | ||
"middle": string; | ||
} | ||
} | ||
declare global { | ||
interface HTMLMyComponentElement extends Components.MyComponent, HTMLStencilElement { | ||
} | ||
var HTMLMyComponentElement: { | ||
prototype: HTMLMyComponentElement; | ||
new (): HTMLMyComponentElement; | ||
}; | ||
interface HTMLElementTagNameMap { | ||
"my-component": HTMLMyComponentElement; | ||
} | ||
} | ||
declare namespace LocalJSX { | ||
interface MyComponent { | ||
/** | ||
* The first name | ||
*/ | ||
"first"?: string; | ||
/** | ||
* The last name | ||
*/ | ||
"last"?: string; | ||
/** | ||
* The middle name | ||
*/ | ||
"middle"?: string; | ||
} | ||
interface IntrinsicElements { | ||
"my-component": MyComponent; | ||
} | ||
} | ||
export { LocalJSX as JSX }; | ||
declare module "@stencil/core" { | ||
export namespace JSX { | ||
interface IntrinsicElements { | ||
"my-component": LocalJSX.MyComponent & JSXBase.HTMLAttributes<HTMLMyComponentElement>; | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
test/bundler/component-library/src/components/my-component/my-component.css
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,3 @@ | ||
:host { | ||
display: block; | ||
} |
32 changes: 32 additions & 0 deletions
32
test/bundler/component-library/src/components/my-component/my-component.tsx
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,32 @@ | ||
import { Component, Prop, h } from '@stencil/core'; | ||
import { format } from '../../utils/utils'; | ||
|
||
@Component({ | ||
tag: 'my-component', | ||
styleUrl: 'my-component.css', | ||
shadow: true, | ||
}) | ||
export class MyComponent { | ||
/** | ||
* The first name | ||
*/ | ||
@Prop() first: string; | ||
|
||
/** | ||
* The middle name | ||
*/ | ||
@Prop() middle: string; | ||
|
||
/** | ||
* The last name | ||
*/ | ||
@Prop() last: string; | ||
|
||
private getText(): string { | ||
return format(this.first, this.middle, this.last); | ||
} | ||
|
||
render() { | ||
return <div>Hello, World! I'm {this.getText()}</div>; | ||
} | ||
} |
Oops, something went wrong.