@open-xchange/vite-plugin-project-meta 1.1.1 → 1.3.0
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.
- package/CHANGELOG.md +8 -0
- package/LICENSE +21 -0
- package/README.md +11 -11
- package/dist/index.d.mts +27 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +61 -0
- package/dist/index.mjs.map +1 -0
- package/dist/virtual.d.ts +29 -28
- package/package.json +13 -22
- package/dist/index.d.ts +0 -22
- package/dist/index.js +0 -56
package/CHANGELOG.md
CHANGED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Open-Xchange GmbH, Germany <info@open-xchange.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ A Vite plugin providing a virtual import for project metadata with build informa
|
|
|
5
5
|
The metadata object can simply be imported in source code as following:
|
|
6
6
|
|
|
7
7
|
```js
|
|
8
|
-
import metadata from
|
|
8
|
+
import metadata from 'virtual:metadata'
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
Additionally, while bundling the project, the plugin will insert a `<meta>` element into all HTML entry files containing a string with random length and contents. This is needed to workaround sticky browser cache when the HTML entry files are being served with weak e-tags that depend on the file size only but not on the file contents.
|
|
@@ -17,8 +17,8 @@ Add the plugin to your Vite configuration:
|
|
|
17
17
|
```ts
|
|
18
18
|
// vite.config.ts
|
|
19
19
|
|
|
20
|
-
import { defineConfig } from
|
|
21
|
-
import metaPlugin from
|
|
20
|
+
import { defineConfig } from 'vite' // or 'vitest/config'
|
|
21
|
+
import metaPlugin from '@open-xchange/vite-plugin-project-meta'
|
|
22
22
|
|
|
23
23
|
export default defineConfig(() => {
|
|
24
24
|
|
|
@@ -28,14 +28,14 @@ export default defineConfig(() => {
|
|
|
28
28
|
// ...
|
|
29
29
|
|
|
30
30
|
metaPlugin({
|
|
31
|
-
id:
|
|
32
|
-
name:
|
|
31
|
+
id: 'my-project-ui'
|
|
32
|
+
name: 'My Project UI',
|
|
33
33
|
}),
|
|
34
34
|
],
|
|
35
35
|
})
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
Register TypeScript type definitions for the
|
|
38
|
+
Register TypeScript type definitions for the 'virtual:metadata' module import:
|
|
39
39
|
|
|
40
40
|
```json
|
|
41
41
|
// src/tsconfig.json
|
|
@@ -55,17 +55,17 @@ Use the virtual module in your code:
|
|
|
55
55
|
```ts
|
|
56
56
|
// src/path/to/some/module.ts
|
|
57
57
|
|
|
58
|
-
import metadata from
|
|
58
|
+
import metadata from 'virtual:metadata'
|
|
59
59
|
|
|
60
|
-
console.log(metadata.id) // from package.json (
|
|
60
|
+
console.log(metadata.id) // from package.json ('name')
|
|
61
61
|
console.log(metadata.name) // from `options.projectName`
|
|
62
|
-
console.log(metadata.version) // from package.json (
|
|
62
|
+
console.log(metadata.version) // from package.json ('version')
|
|
63
63
|
console.log(metadata.builddate) // plugin execution timestamp
|
|
64
|
-
console.log(metadata.commitsha) // from env variable
|
|
64
|
+
console.log(metadata.commitsha) // from env variable 'CI_COMMIT_SHA'
|
|
65
65
|
```
|
|
66
66
|
|
|
67
67
|
### Options
|
|
68
68
|
|
|
69
69
|
| Name | Type | Default | Description |
|
|
70
70
|
| - | - | - | - |
|
|
71
|
-
| `projectName` | `string` | _required_ | Display name of the project, for metadata property
|
|
71
|
+
| `projectName` | `string` | _required_ | Display name of the project, for metadata property 'name'. |
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Plugin } from "vite";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Configuration options for the plugin '@open-xchange/vite-plugin-project-meta'.
|
|
6
|
+
*/
|
|
7
|
+
interface VitePluginProjectMetaOptions {
|
|
8
|
+
/**
|
|
9
|
+
* The display name of the project.
|
|
10
|
+
*/
|
|
11
|
+
projectName: string;
|
|
12
|
+
}
|
|
13
|
+
declare const PROJECT_NAME = "@open-xchange/vite-plugin-project-meta";
|
|
14
|
+
/**
|
|
15
|
+
* Vite plugin that provides a virtual module 'virtual:metadata' exporting a
|
|
16
|
+
* metadata object with project build information (timestamp, commit ID, etc.).
|
|
17
|
+
*
|
|
18
|
+
* @param options
|
|
19
|
+
* Plugin configuration.
|
|
20
|
+
*
|
|
21
|
+
* @returns
|
|
22
|
+
* The Vite plugin object.
|
|
23
|
+
*/
|
|
24
|
+
declare function vitePluginProjectMeta(options: VitePluginProjectMetaOptions): Plugin;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { PROJECT_NAME, VitePluginProjectMetaOptions, vitePluginProjectMeta as default };
|
|
27
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;AAcA;UAAiB,4BAAA;;;;EAKf,WAAA;AAAA;AAAA,cAKW,YAAA;;;AAAuD;;;;;;;;iBAc5C,qBAAA,CAAsB,OAAA,EAAS,4BAAA,GAA+B,MAAA"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
//#region src/index.ts
|
|
5
|
+
const PROJECT_NAME = "@open-xchange/vite-plugin-project-meta";
|
|
6
|
+
/**
|
|
7
|
+
* Vite plugin that provides a virtual module 'virtual:metadata' exporting a
|
|
8
|
+
* metadata object with project build information (timestamp, commit ID, etc.).
|
|
9
|
+
*
|
|
10
|
+
* @param options
|
|
11
|
+
* Plugin configuration.
|
|
12
|
+
*
|
|
13
|
+
* @returns
|
|
14
|
+
* The Vite plugin object.
|
|
15
|
+
*/
|
|
16
|
+
function vitePluginProjectMeta(options) {
|
|
17
|
+
const MODULE_NAME = "virtual:metadata";
|
|
18
|
+
const MODULE_ID = `\0${PROJECT_NAME}/${MODULE_NAME}`;
|
|
19
|
+
let metadata;
|
|
20
|
+
return {
|
|
21
|
+
name: PROJECT_NAME,
|
|
22
|
+
configResolved(config) {
|
|
23
|
+
const pkg = JSON.parse(readFileSync(join(config.root, "package.json"), { encoding: "utf8" }));
|
|
24
|
+
metadata = {
|
|
25
|
+
id: pkg.name,
|
|
26
|
+
name: options.projectName,
|
|
27
|
+
version: pkg.version,
|
|
28
|
+
builddate: (/* @__PURE__ */ new Date()).toISOString(),
|
|
29
|
+
commitsha: process.env.CI_COMMIT_SHA
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
resolveId(source) {
|
|
33
|
+
return source === MODULE_NAME ? MODULE_ID : null;
|
|
34
|
+
},
|
|
35
|
+
load(id) {
|
|
36
|
+
if (id !== MODULE_ID) return null;
|
|
37
|
+
return {
|
|
38
|
+
code: `export default ${JSON.stringify(metadata)};`,
|
|
39
|
+
map: { mappings: "" }
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
transformIndexHtml(_html, context) {
|
|
43
|
+
if (!context.bundle) return;
|
|
44
|
+
const hash = createHash("md5").update(metadata.builddate).digest("hex");
|
|
45
|
+
const len = Number.parseInt(hash.slice(0, 4), 16) % 99 + 42;
|
|
46
|
+
const count = Math.ceil(len / hash.length);
|
|
47
|
+
return [{
|
|
48
|
+
tag: "meta",
|
|
49
|
+
attrs: {
|
|
50
|
+
name: "etag-fix",
|
|
51
|
+
content: hash.repeat(count).slice(0, len)
|
|
52
|
+
},
|
|
53
|
+
injectTo: "head"
|
|
54
|
+
}];
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
export { PROJECT_NAME, vitePluginProjectMeta as default };
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["\nimport { join } from 'node:path'\nimport { readFileSync } from 'node:fs'\nimport { createHash } from 'node:crypto'\n\nimport type { Plugin } from 'vite'\n\nimport type { VirtualProjectMetadata } from 'virtual:metadata'\n\n// types ======================================================================\n\n/**\n * Configuration options for the plugin '@open-xchange/vite-plugin-project-meta'.\n */\nexport interface VitePluginProjectMetaOptions {\n\n /**\n * The display name of the project.\n */\n projectName: string\n}\n\n// constants ==================================================================\n\nexport const PROJECT_NAME = '@open-xchange/vite-plugin-project-meta'\n\n// plugin =====================================================================\n\n/**\n * Vite plugin that provides a virtual module 'virtual:metadata' exporting a\n * metadata object with project build information (timestamp, commit ID, etc.).\n *\n * @param options\n * Plugin configuration.\n *\n * @returns\n * The Vite plugin object.\n */\nexport default function vitePluginProjectMeta(options: VitePluginProjectMetaOptions): Plugin {\n\n const MODULE_NAME = 'virtual:metadata'\n const MODULE_ID = `\\0${PROJECT_NAME}/${MODULE_NAME}`\n\n let metadata: VirtualProjectMetadata\n\n return {\n name: PROJECT_NAME,\n\n configResolved(config) {\n /** @ignore */\n interface Package {\n name: string\n version: string\n }\n const pkg = JSON.parse(readFileSync(join(config.root, 'package.json'), { encoding: 'utf8' })) as Package\n metadata = {\n id: pkg.name,\n name: options.projectName,\n version: pkg.version,\n builddate: new Date().toISOString(),\n commitsha: process.env.CI_COMMIT_SHA,\n }\n },\n\n resolveId(source) {\n return (source === MODULE_NAME) ? MODULE_ID : null\n },\n\n load(id) {\n if (id !== MODULE_ID) { return null }\n const code = `export default ${JSON.stringify(metadata)};`\n return { code, map: { mappings: '' } }\n },\n\n transformIndexHtml(_html, context) {\n if (!context.bundle) { return }\n const hash = createHash('md5').update(metadata.builddate).digest('hex')\n const len = Number.parseInt(hash.slice(0, 4), 16) % 99 + 42\n const count = Math.ceil(len / hash.length)\n const content = hash.repeat(count).slice(0, len)\n const attrs = { name: 'etag-fix', content }\n // inject a <meta> element into the <head>\n return [{ tag: 'meta', attrs, injectTo: 'head' }]\n },\n }\n}\n"],"mappings":";;;;AAwBA,MAAa,eAAe;;;;;;;;;;;AAc5B,SAAwB,sBAAsB,SAA+C;CAE3F,MAAM,cAAc;CACpB,MAAM,YAAY,KAAK,aAAa,GAAG;CAEvC,IAAI;AAEJ,QAAO;EACL,MAAM;EAEN,eAAe,QAAQ;GAMrB,MAAM,MAAM,KAAK,MAAM,aAAa,KAAK,OAAO,MAAM,eAAe,EAAE,EAAE,UAAU,QAAQ,CAAC,CAAC;AAC7F,cAAW;IACT,IAAI,IAAI;IACR,MAAM,QAAQ;IACd,SAAS,IAAI;IACb,4BAAW,IAAI,MAAM,EAAC,aAAa;IACnC,WAAW,QAAQ,IAAI;IACxB;;EAGH,UAAU,QAAQ;AAChB,UAAQ,WAAW,cAAe,YAAY;;EAGhD,KAAK,IAAI;AACP,OAAI,OAAO,UAAa,QAAO;AAE/B,UAAO;IAAE,MADI,kBAAkB,KAAK,UAAU,SAAS,CAAC;IACzC,KAAK,EAAE,UAAU,IAAI;IAAE;;EAGxC,mBAAmB,OAAO,SAAS;AACjC,OAAI,CAAC,QAAQ,OAAU;GACvB,MAAM,OAAO,WAAW,MAAM,CAAC,OAAO,SAAS,UAAU,CAAC,OAAO,MAAM;GACvE,MAAM,MAAM,OAAO,SAAS,KAAK,MAAM,GAAG,EAAE,EAAE,GAAG,GAAG,KAAK;GACzD,MAAM,QAAQ,KAAK,KAAK,MAAM,KAAK,OAAO;AAI1C,UAAO,CAAC;IAAE,KAAK;IAAQ,OAFT;KAAE,MAAM;KAAY,SADlB,KAAK,OAAO,MAAM,CAAC,MAAM,GAAG,IAAI;KACL;IAEb,UAAU;IAAQ,CAAC;;EAEpD"}
|
package/dist/virtual.d.ts
CHANGED
|
@@ -1,37 +1,38 @@
|
|
|
1
|
-
declare module
|
|
1
|
+
declare module 'virtual:metadata' {
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Shape of the metadata object provided by the virtual module
|
|
5
|
+
* 'virtual:metadata'.
|
|
6
|
+
*/
|
|
7
|
+
export interface VirtualProjectMetadata {
|
|
2
8
|
|
|
3
9
|
/**
|
|
4
|
-
*
|
|
10
|
+
* Internal identifier of the project.
|
|
5
11
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Internal identifier of the project.
|
|
10
|
-
*/
|
|
11
|
-
id: string;
|
|
12
|
+
id: string
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
/**
|
|
15
|
+
* The display name of the project.
|
|
16
|
+
*/
|
|
17
|
+
name: string
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
/**
|
|
20
|
+
* The version string of the package.
|
|
21
|
+
*/
|
|
22
|
+
version: string
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
/**
|
|
25
|
+
* The date when the package was built (ISO timestamp).
|
|
26
|
+
*/
|
|
27
|
+
builddate: string
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
/**
|
|
30
|
+
* The identifier of the last GIT commit the package has been built on.
|
|
31
|
+
* Will be picked from the environment variable 'CI_COMMIT_SHA'.
|
|
32
|
+
*/
|
|
33
|
+
commitsha: string | undefined
|
|
34
|
+
}
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
const metadata: VirtualProjectMetadata
|
|
37
|
+
export default metadata
|
|
37
38
|
}
|
package/package.json
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-xchange/vite-plugin-project-meta",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Vite plugin providing a virtual import for project metadata",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "https://gitlab.open-xchange.com/fspd/commons/plugins",
|
|
7
|
+
"url": "git+https://gitlab.open-xchange.com/fspd/commons/plugins.git",
|
|
8
8
|
"directory": "packages/vite-plugin-project-meta"
|
|
9
9
|
},
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"engines": {
|
|
12
12
|
"node": ">=20.18"
|
|
13
13
|
},
|
|
14
|
-
"packageManager": "yarn@4.9.4",
|
|
15
14
|
"type": "module",
|
|
16
15
|
"exports": {
|
|
17
|
-
".":
|
|
18
|
-
|
|
19
|
-
"default": "./dist/index.js"
|
|
20
|
-
},
|
|
16
|
+
".": "./dist/index.mjs",
|
|
17
|
+
"./package.json": "./package.json",
|
|
21
18
|
"./virtual": {
|
|
22
19
|
"types": "./dist/virtual.d.ts"
|
|
23
20
|
}
|
|
@@ -26,23 +23,17 @@
|
|
|
26
23
|
"dist",
|
|
27
24
|
"CHANGELOG.*"
|
|
28
25
|
],
|
|
29
|
-
"scripts": {
|
|
30
|
-
"prepack": "yarn build && yarn lint",
|
|
31
|
-
"clean": "premove dist",
|
|
32
|
-
"build": "yarn clean && tsc --project src/tsconfig.json && cpx src/virtual.d.ts dist/",
|
|
33
|
-
"lint": "tsc && tsc --project src/tsconfig.json --noEmit && eslint ."
|
|
34
|
-
},
|
|
35
26
|
"devDependencies": {
|
|
36
|
-
"
|
|
37
|
-
"@
|
|
38
|
-
"
|
|
39
|
-
"eslint": "^9.35.0",
|
|
40
|
-
"jiti": "^2.5.1",
|
|
41
|
-
"premove": "^4.0.0",
|
|
42
|
-
"typescript": "^5.9.2",
|
|
43
|
-
"vite": "^7.1.5"
|
|
27
|
+
"vite": "^8.0.8",
|
|
28
|
+
"@open-xchange/linter-presets": "^1.22.0",
|
|
29
|
+
"@open-xchange/tsconfig": "^0.0.2"
|
|
44
30
|
},
|
|
45
31
|
"peerDependencies": {
|
|
46
|
-
"vite": "^6.0.0 || ^7.0.0"
|
|
32
|
+
"vite": "^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsdown",
|
|
36
|
+
"lint": "tsc && tsc --project src && eslint .",
|
|
37
|
+
"verify": "pnpm build && pnpm lint"
|
|
47
38
|
}
|
|
48
39
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { Plugin } from "vite";
|
|
2
|
-
/**
|
|
3
|
-
* Configuration options for the plugin "@open-xchange/vite-plugin-project-meta".
|
|
4
|
-
*/
|
|
5
|
-
export interface VitePluginProjectMetaOptions {
|
|
6
|
-
/**
|
|
7
|
-
* The display name of the project.
|
|
8
|
-
*/
|
|
9
|
-
projectName: string;
|
|
10
|
-
}
|
|
11
|
-
export declare const PROJECT_NAME = "@open-xchange/vite-plugin-project-meta";
|
|
12
|
-
/**
|
|
13
|
-
* Vite plugin that provides a virtual module "virtual:metadata" exporting a
|
|
14
|
-
* metadata object with project build information (timestamp, commit ID, etc.).
|
|
15
|
-
*
|
|
16
|
-
* @param options
|
|
17
|
-
* Plugin configuration.
|
|
18
|
-
*
|
|
19
|
-
* @returns
|
|
20
|
-
* The Vite plugin object.
|
|
21
|
-
*/
|
|
22
|
-
export default function vitePluginProjectMeta(options: VitePluginProjectMetaOptions): Plugin;
|
package/dist/index.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
2
|
-
import { readFileSync } from "node:fs";
|
|
3
|
-
import { createHash } from "node:crypto";
|
|
4
|
-
// constants ==================================================================
|
|
5
|
-
export const PROJECT_NAME = "@open-xchange/vite-plugin-project-meta";
|
|
6
|
-
// plugin =====================================================================
|
|
7
|
-
/**
|
|
8
|
-
* Vite plugin that provides a virtual module "virtual:metadata" exporting a
|
|
9
|
-
* metadata object with project build information (timestamp, commit ID, etc.).
|
|
10
|
-
*
|
|
11
|
-
* @param options
|
|
12
|
-
* Plugin configuration.
|
|
13
|
-
*
|
|
14
|
-
* @returns
|
|
15
|
-
* The Vite plugin object.
|
|
16
|
-
*/
|
|
17
|
-
export default function vitePluginProjectMeta(options) {
|
|
18
|
-
const MODULE_NAME = "virtual:metadata";
|
|
19
|
-
const MODULE_ID = `\0${PROJECT_NAME}/${MODULE_NAME}`;
|
|
20
|
-
let metadata;
|
|
21
|
-
return {
|
|
22
|
-
name: PROJECT_NAME,
|
|
23
|
-
configResolved(config) {
|
|
24
|
-
const pkg = JSON.parse(readFileSync(join(config.root, "package.json"), { encoding: "utf8" }));
|
|
25
|
-
metadata = {
|
|
26
|
-
id: pkg.name,
|
|
27
|
-
name: options.projectName,
|
|
28
|
-
version: pkg.version,
|
|
29
|
-
builddate: new Date().toISOString(),
|
|
30
|
-
commitsha: process.env.CI_COMMIT_SHA,
|
|
31
|
-
};
|
|
32
|
-
},
|
|
33
|
-
resolveId(source) {
|
|
34
|
-
return (source === MODULE_NAME) ? MODULE_ID : null;
|
|
35
|
-
},
|
|
36
|
-
load(id) {
|
|
37
|
-
if (id !== MODULE_ID) {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
const code = `export default ${JSON.stringify(metadata)};`;
|
|
41
|
-
return { code, map: { mappings: "" } };
|
|
42
|
-
},
|
|
43
|
-
transformIndexHtml(_html, context) {
|
|
44
|
-
if (!context.bundle) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
const hash = createHash("md5").update(metadata.builddate).digest("hex");
|
|
48
|
-
const len = Number.parseInt(hash.slice(0, 4), 16) % 99 + 42;
|
|
49
|
-
const count = Math.ceil(len / hash.length);
|
|
50
|
-
const content = hash.repeat(count).slice(0, len);
|
|
51
|
-
const attrs = { name: "etag-fix", content };
|
|
52
|
-
// inject a <meta> element into the <head>
|
|
53
|
-
return [{ tag: "meta", attrs, injectTo: "head" }];
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
}
|