Skip to content
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

docs(compiler): add type docs for esmLoaderPath #1364

Merged
merged 7 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions docs/output-targets/dist.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,47 @@ import * as utils from '../path/to/utils';
If using the `dist-collection` output target directly, the same result can be achieved using the [`transformAliasedImportPaths`](../output-targets/dist.md#transformaliasedimportpathsincollection) flag on the target's config.
:::

### esmLoaderPath

*default: `/dist/loader`*

Provide a custom path for the ESM loader directory, containing files you can import in an initiation script within your application to register all your components for lazy loading. Read more about the loader directory in the [section below](#loader).

If you don't use a custom [exports](https://nodejs.org/api/packages.html#exports) map, users would have to import the loader script via:

```js
import { defineCustomElements } from 'stencil-library/dist/loader'
```

By setting `esmLoaderPath` to e.g. `../loader` you can shorten or rename the import path to:

```js
import { defineCustomElements } from 'stencil-library/loader'
```

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we expand on this? I'm not sure that as a user, I'd know enough here to start using this flag. To start, it might be worthwhile to include an example directory structure, setting with a custom value for esmLoaderPath, and explaining how setting esmLoaderPath affects the output of Stencil.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. Maybe we need an additional section that talks about lazy loading and what the loader does? We could pull some of this out of the "How is this different from "dist-custom-elements" output target?" section.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a section to the loader script and also added an example how modifying the option has an impact on the user of a stencil library.

## Publishing

Next you can publish your library to [Node Package Manager (NPM)](https://www.npmjs.com/). For more information about setting up the `package.json` file, and publishing, see: [Publishing A Component Library](../guides/publishing.md).

## Loader

The `dist` output target generates a loader directory that exports an `setNonce`, `applyPolyfills` and `defineCustomElements` helper function when imported within an ESM context. This allows you to register all components of your library to be used in your project in an application setup script, e.g.:
christian-bromann marked this conversation as resolved.
Show resolved Hide resolved

```ts
import { applyPolyfills, defineCustomElements, setNonce } from 'stencil-library/loader';

// Will set the `nonce` attribute for all scripts/style tags
// i.e. will run styleTag.setAttribute('nonce', 'r4nd0m')
// Obviously, you should use the nonce generated by your server
setNonce('r4nd0m');

applyPolyfills().then(() => {
defineCustomElements();
});
```

This is an alternative approach to e.g. loading the components directly through a script tag as mentioned below. Read more about `setNonce` and when to set it in our guide on [Content Security Policy Nonces](../guides/csp-nonce.md).

## Distribution Options

Each output target's form of bundling and distribution has its own pros and cons. Luckily you can just worry about writing good source code for your component. Stencil will handle generating the various bundles and consumers of your library can decide how to apply your components to their external projects. Below are a few of the options.
Expand Down
6 changes: 6 additions & 0 deletions versioned_docs/version-v3/output-targets/dist.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ This flag defaults to `false` when omitted from a Stencil configuration file.
If using the `dist-collection` output target directly, the same result can be achieved using the `transformAliasedImportPaths` flag on the target's config.
:::

### esmLoaderPath

*default: `/dist/loader`*

Provide a custom path for the ESM loader directory, containing files you can import in an initiation script within your application to register all your components for lazy loading.

## Publishing

Next you can publish your library to [Node Package Manager (NPM)](https://www.npmjs.com/). For more information about setting up the `package.json` file, and publishing, see: [Publishing A Component Library](../guides/publishing.md).
Expand Down
6 changes: 6 additions & 0 deletions versioned_docs/version-v4.0/output-targets/dist.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ import * as utils from '../path/to/utils';
If using the `dist-collection` output target directly, the same result can be achieved using the [`transformAliasedImportPaths`](../output-targets/dist.md#transformaliasedimportpathsincollection) flag on the target's config.
:::

### esmLoaderPath

*default: `/dist/loader`*

Provide a custom path for the ESM loader directory, containing files you can import in an initiation script within your application to register all your components for lazy loading.

## Publishing

Next you can publish your library to [Node Package Manager (NPM)](https://www.npmjs.com/). For more information about setting up the `package.json` file, and publishing, see: [Publishing A Component Library](../guides/publishing.md).
Expand Down
6 changes: 6 additions & 0 deletions versioned_docs/version-v4.1/output-targets/dist.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ import * as utils from '../path/to/utils';
If using the `dist-collection` output target directly, the same result can be achieved using the [`transformAliasedImportPaths`](../output-targets/dist.md#transformaliasedimportpathsincollection) flag on the target's config.
:::

### esmLoaderPath

*default: `/dist/loader`*

Provide a custom path for the ESM loader directory, containing files you can import in an initiation script within your application to register all your components for lazy loading.

## Publishing

Next you can publish your library to [Node Package Manager (NPM)](https://www.npmjs.com/). For more information about setting up the `package.json` file, and publishing, see: [Publishing A Component Library](../guides/publishing.md).
Expand Down
6 changes: 6 additions & 0 deletions versioned_docs/version-v4.10/output-targets/dist.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ import * as utils from '../path/to/utils';
If using the `dist-collection` output target directly, the same result can be achieved using the [`transformAliasedImportPaths`](../output-targets/dist.md#transformaliasedimportpathsincollection) flag on the target's config.
:::

### esmLoaderPath

*default: `/dist/loader`*

Provide a custom path for the ESM loader directory, containing files you can import in an initiation script within your application to register all your components for lazy loading.

## Publishing

Next you can publish your library to [Node Package Manager (NPM)](https://www.npmjs.com/). For more information about setting up the `package.json` file, and publishing, see: [Publishing A Component Library](../guides/publishing.md).
Expand Down
6 changes: 6 additions & 0 deletions versioned_docs/version-v4.11/output-targets/dist.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ import * as utils from '../path/to/utils';
If using the `dist-collection` output target directly, the same result can be achieved using the [`transformAliasedImportPaths`](../output-targets/dist.md#transformaliasedimportpathsincollection) flag on the target's config.
:::

### esmLoaderPath

*default: `/dist/loader`*

Provide a custom path for the ESM loader directory, containing files you can import in an initiation script within your application to register all your components for lazy loading.

## Publishing

Next you can publish your library to [Node Package Manager (NPM)](https://www.npmjs.com/). For more information about setting up the `package.json` file, and publishing, see: [Publishing A Component Library](../guides/publishing.md).
Expand Down
6 changes: 6 additions & 0 deletions versioned_docs/version-v4.12/output-targets/dist.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ import * as utils from '../path/to/utils';
If using the `dist-collection` output target directly, the same result can be achieved using the [`transformAliasedImportPaths`](../output-targets/dist.md#transformaliasedimportpathsincollection) flag on the target's config.
:::

### esmLoaderPath

*default: `/dist/loader`*

Provide a custom path for the ESM loader directory, containing files you can import in an initiation script within your application to register all your components for lazy loading.

## Publishing

Next you can publish your library to [Node Package Manager (NPM)](https://www.npmjs.com/). For more information about setting up the `package.json` file, and publishing, see: [Publishing A Component Library](../guides/publishing.md).
Expand Down
6 changes: 6 additions & 0 deletions versioned_docs/version-v4.2/output-targets/dist.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ import * as utils from '../path/to/utils';
If using the `dist-collection` output target directly, the same result can be achieved using the [`transformAliasedImportPaths`](../output-targets/dist.md#transformaliasedimportpathsincollection) flag on the target's config.
:::

### esmLoaderPath

*default: `/dist/loader`*

Provide a custom path for the ESM loader directory, containing files you can import in an initiation script within your application to register all your components for lazy loading.

## Publishing

Next you can publish your library to [Node Package Manager (NPM)](https://www.npmjs.com/). For more information about setting up the `package.json` file, and publishing, see: [Publishing A Component Library](../guides/publishing.md).
Expand Down
6 changes: 6 additions & 0 deletions versioned_docs/version-v4.3/output-targets/dist.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ import * as utils from '../path/to/utils';
If using the `dist-collection` output target directly, the same result can be achieved using the [`transformAliasedImportPaths`](../output-targets/dist.md#transformaliasedimportpathsincollection) flag on the target's config.
:::

### esmLoaderPath

*default: `/dist/loader`*

Provide a custom path for the ESM loader directory, containing files you can import in an initiation script within your application to register all your components for lazy loading.

## Publishing

Next you can publish your library to [Node Package Manager (NPM)](https://www.npmjs.com/). For more information about setting up the `package.json` file, and publishing, see: [Publishing A Component Library](../guides/publishing.md).
Expand Down
6 changes: 6 additions & 0 deletions versioned_docs/version-v4.4/output-targets/dist.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ import * as utils from '../path/to/utils';
If using the `dist-collection` output target directly, the same result can be achieved using the [`transformAliasedImportPaths`](../output-targets/dist.md#transformaliasedimportpathsincollection) flag on the target's config.
:::

### esmLoaderPath

*default: `/dist/loader`*

Provide a custom path for the ESM loader directory, containing files you can import in an initiation script within your application to register all your components for lazy loading.

## Publishing

Next you can publish your library to [Node Package Manager (NPM)](https://www.npmjs.com/). For more information about setting up the `package.json` file, and publishing, see: [Publishing A Component Library](../guides/publishing.md).
Expand Down
6 changes: 6 additions & 0 deletions versioned_docs/version-v4.5/output-targets/dist.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ import * as utils from '../path/to/utils';
If using the `dist-collection` output target directly, the same result can be achieved using the [`transformAliasedImportPaths`](../output-targets/dist.md#transformaliasedimportpathsincollection) flag on the target's config.
:::

### esmLoaderPath

*default: `/dist/loader`*

Provide a custom path for the ESM loader directory, containing files you can import in an initiation script within your application to register all your components for lazy loading.

## Publishing

Next you can publish your library to [Node Package Manager (NPM)](https://www.npmjs.com/). For more information about setting up the `package.json` file, and publishing, see: [Publishing A Component Library](../guides/publishing.md).
Expand Down
6 changes: 6 additions & 0 deletions versioned_docs/version-v4.6/output-targets/dist.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ import * as utils from '../path/to/utils';
If using the `dist-collection` output target directly, the same result can be achieved using the [`transformAliasedImportPaths`](../output-targets/dist.md#transformaliasedimportpathsincollection) flag on the target's config.
:::

### esmLoaderPath

*default: `/dist/loader`*

Provide a custom path for the ESM loader directory, containing files you can import in an initiation script within your application to register all your components for lazy loading.

## Publishing

Next you can publish your library to [Node Package Manager (NPM)](https://www.npmjs.com/). For more information about setting up the `package.json` file, and publishing, see: [Publishing A Component Library](../guides/publishing.md).
Expand Down
6 changes: 6 additions & 0 deletions versioned_docs/version-v4.7/output-targets/dist.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ import * as utils from '../path/to/utils';
If using the `dist-collection` output target directly, the same result can be achieved using the [`transformAliasedImportPaths`](../output-targets/dist.md#transformaliasedimportpathsincollection) flag on the target's config.
:::

### esmLoaderPath

*default: `/dist/loader`*

Provide a custom path for the ESM loader directory, containing files you can import in an initiation script within your application to register all your components for lazy loading.

## Publishing

Next you can publish your library to [Node Package Manager (NPM)](https://www.npmjs.com/). For more information about setting up the `package.json` file, and publishing, see: [Publishing A Component Library](../guides/publishing.md).
Expand Down
6 changes: 6 additions & 0 deletions versioned_docs/version-v4.8/output-targets/dist.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ import * as utils from '../path/to/utils';
If using the `dist-collection` output target directly, the same result can be achieved using the [`transformAliasedImportPaths`](../output-targets/dist.md#transformaliasedimportpathsincollection) flag on the target's config.
:::

### esmLoaderPath

*default: `/dist/loader`*

Provide a custom path for the ESM loader directory, containing files you can import in an initiation script within your application to register all your components for lazy loading.

## Publishing

Next you can publish your library to [Node Package Manager (NPM)](https://www.npmjs.com/). For more information about setting up the `package.json` file, and publishing, see: [Publishing A Component Library](../guides/publishing.md).
Expand Down
6 changes: 6 additions & 0 deletions versioned_docs/version-v4.9/output-targets/dist.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ import * as utils from '../path/to/utils';
If using the `dist-collection` output target directly, the same result can be achieved using the [`transformAliasedImportPaths`](../output-targets/dist.md#transformaliasedimportpathsincollection) flag on the target's config.
:::

### esmLoaderPath

*default: `/dist/loader`*

Provide a custom path for the ESM loader directory, containing files you can import in an initiation script within your application to register all your components for lazy loading.

## Publishing

Next you can publish your library to [Node Package Manager (NPM)](https://www.npmjs.com/). For more information about setting up the `package.json` file, and publishing, see: [Publishing A Component Library](../guides/publishing.md).
Expand Down