-
Notifications
You must be signed in to change notification settings - Fork 137
/
rollup.ts
108 lines (97 loc) · 3.61 KB
/
rollup.ts
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { default as hbs } from './rollup-hbs-plugin';
import { default as gjs } from './rollup-gjs-plugin';
import { default as publicEntrypoints } from './rollup-public-entrypoints';
import { default as appReexports } from './rollup-app-reexports';
import type { Options as DelOptions } from 'rollup-plugin-delete';
import { default as clean } from 'rollup-plugin-delete';
import { default as keepAssets } from './rollup-keep-assets';
import { default as dependencies } from './rollup-addon-dependencies';
import { default as publicAssets } from './rollup-public-assets';
import type { Plugin } from 'rollup';
export class Addon {
#srcDir: string;
#destDir: string;
constructor(params: { srcDir?: string; destDir?: string } = {}) {
this.#srcDir = params.srcDir ?? 'src';
this.#destDir = params.destDir ?? 'dist';
}
// Given a list of globs describing modules in your srcDir, this generates
// corresponding appTree modules that contain reexports, and updates your
// package.json metadata to list them all.
appReexports(
patterns: string[],
opts: {
mapFilename?: (fileName: string) => string;
exports?: (filename: string) => string[] | string | undefined;
exclude?: string[];
} = {}
): Plugin {
return appReexports({
from: this.#srcDir,
to: this.#destDir,
include: patterns,
mapFilename: opts.mapFilename,
exports: opts.exports,
exclude: opts.exclude,
});
}
// This configures rollup to emit public entrypoints for each module in your
// srcDir that matches one of the given globs. Typical addons will want to
// match patterns like "components/**/*.js", "index.js", and "test-support.js".
publicEntrypoints(patterns: string[], opts: { exclude?: string[] } = {}) {
return publicEntrypoints({
srcDir: this.#srcDir,
include: patterns,
exclude: opts.exclude,
});
}
// This wraps standalone .hbs files as Javascript files using inline
// templates. This means special resolving rules for .hbs files aren't
// required for javascript tooling to understand your package.
hbs() {
return hbs();
}
gjs(options?: { inline_source_map: boolean }) {
return gjs(options);
}
// By default rollup does not clear the output directory between builds. This
// does that.
clean(options: DelOptions) {
return clean({ targets: `${this.#destDir}/*`, ...options });
}
// V2 Addons are allowed to contain imports of .css files. This tells rollup
// to leave those imports alone and to make sure the corresponding .css files
// are kept in the same relative locations in the destDir as they were in the
// srcDir.
keepAssets(patterns: string[]) {
return keepAssets({
from: this.#srcDir,
include: patterns,
});
}
// This is the default `output` configuration you should pass to rollup. We're
// emitting ES modules, in your `destDir`, and their filenames are equal to
// their bundle names (the bundle names get generated by `publicEntrypoints`
// above).
//
// hoistTransitiveImports is disabled because the purpose of hoisting transitive imports
// is to improve performance of apps loading modules.
// Since v2 addons do not know exactly how they'll be used, this performance decision
// is left up to apps.
output() {
return {
dir: this.#destDir,
entryFileNames: '[name]',
experimentalMinChunkSize: 0,
format: 'es',
hoistTransitiveImports: false,
sourcemap: true,
};
}
dependencies() {
return dependencies();
}
publicAssets(path: string, opts: { include: string[]; exclude: string[] }) {
return publicAssets(path, opts);
}
}