forked from stenciljs/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloader-plugin.ts
More file actions
43 lines (42 loc) · 1.9 KB
/
Copy pathloader-plugin.ts
File metadata and controls
43 lines (42 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import type { LoadResult, Plugin, ResolveIdResult } from 'rollup';
/**
* Rollup plugin that aids in resolving the entry points (1 or more files) for a Stencil project. For example, a project
* using the `dist-custom-elements` output target may have a single 'entry point' for each file containing a component.
* Each of those files will be independently resolved and loaded by this plugin for further processing by Rollup later
* in the bundling process.
*
* @param entries the Stencil project files to process. It should be noted that the keys in this object may not
* necessarily be an absolute or relative path to a file, but may be a Rollup Virtual Module (which begin with \0).
* @returns the rollup plugin that loads and process a Stencil project's entry points
*/
export const loaderPlugin = (entries: { [id: string]: string } = {}): Plugin => {
return {
name: 'stencilLoaderPlugin',
/**
* A rollup build hook for resolving the imports of individual Stencil project files. This hook only resolves
* modules that are contained in the plugin's `entries` argument. [Source](https://rollupjs.org/guide/en/#resolveid)
* @param id the importee to resolve
* @returns a string that resolves an import to some id, null otherwise
*/
resolveId(id: string): ResolveIdResult {
if (id in entries) {
return {
id,
};
}
return null;
},
/**
* A rollup build hook for loading individual Stencil project files [Source](https://rollupjs.org/guide/en/#load)
* @param id the path of the module to load. It should be noted that the keys in this object may not necessarily
* be an absolute or relative path to a file, but may be a Rollup Virtual Module.
* @returns the module matched, null otherwise
*/
load(id: string): LoadResult {
if (id in entries) {
return entries[id];
}
return null;
},
};
};