@m2c2kit/build-helpers 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.d.ts +55 -0
  2. package/dist/index.js +12339 -0
  3. package/package.json +43 -0
@@ -0,0 +1,55 @@
1
+ import { InputOptions } from 'rollup';
2
+
3
+ /**
4
+ * rollup plugin to hash m2c2kit assets and enable cache busting.
5
+ *
6
+ * @remarks On repeated deployments, a file with the same name may be
7
+ * cached by browsers. Thus, the old file will be used, not the updated
8
+ * one. To enable cache busting, this rollup plugin adds hashes to filenames
9
+ * for m2c2kit assets: index.js, canvaskit.wasm, images, and fonts. This is
10
+ * done by: 1) parsing index.html and finding the links to css and index.js,
11
+ * calculating a hash of these assets, adding a hash to the asset filenames,
12
+ * and updating the links in index.html to reflect the hash. 2) parsing
13
+ * index.js into an AST, finding string literals that are the urls of fonts,
14
+ * images, and canvaskit.wam, calculating a hash of these assets, adding a
15
+ * hash to the asset filenames, and updating the urls to reflect the hash.
16
+ *
17
+ * Note: index.js is transpiled from TypeScript and no longer has types, so
18
+ * finding the asset urls in the AST assumes that there will be no
19
+ * user code with the same structure as the asset urls. In other words:
20
+ * Don't use a define a property named "canvasKitWasmUrl" that refers to
21
+ * a string literal, don't define a property named "fontUrls" that refers
22
+ * to an array expression of string literals, and don't define a property
23
+ * called "images" that refers to an array expression of object expressions
24
+ * with properties named "imageName", "height", "width", and "url". Otherwise,
25
+ * this plugin may alter your code in unexpected ways (although most likely
26
+ * it will simply give warnings, because it's unlikely there will be valid
27
+ * file assets that will be found and hashed).
28
+ *
29
+ * @param rootDir - root directory of build, usually "dist" because you
30
+ * usually hash only production builds
31
+ * @returns
32
+ */
33
+ declare function hashM2c2kitAssets(rootDir: string): {
34
+ name: string;
35
+ closeBundle: {
36
+ sequential: boolean;
37
+ handler(): Promise<void>;
38
+ };
39
+ };
40
+
41
+ declare function makeM2c2kitServiceWorker(rootDir: string, additionalFiles?: Array<string>): {
42
+ name: string;
43
+ buildStart: {
44
+ handler(options: InputOptions): void;
45
+ };
46
+ transform: {
47
+ handler(code: string, id: any): string;
48
+ };
49
+ closeBundle: {
50
+ sequential: boolean;
51
+ handler(): Promise<void>;
52
+ };
53
+ };
54
+
55
+ export { hashM2c2kitAssets, makeM2c2kitServiceWorker };