@open-xchange/vite-plugin-project-meta 0.0.1 → 0.0.3
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/README.md +8 -0
- package/dist/index.js +15 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.3] - 2024-07-30
|
|
4
|
+
|
|
5
|
+
- changed: e-tag hash depends on build date instead of package version
|
|
6
|
+
|
|
7
|
+
## [0.0.2] - 2024-07-30
|
|
8
|
+
|
|
9
|
+
- added: generate `<meta name="etag-fix" ...>` for HTML entry files
|
|
10
|
+
|
|
3
11
|
## [0.0.1] - 2024-07-30
|
|
4
12
|
|
|
5
13
|
- initial release
|
package/README.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
A Vite plugin providing a virtual import for project metadata with build information.
|
|
4
4
|
|
|
5
|
+
The metadata object can simply be imported in source code as following:
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
import metadata from "virtual:metadata"
|
|
9
|
+
```
|
|
10
|
+
|
|
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.
|
|
12
|
+
|
|
5
13
|
## Usage
|
|
6
14
|
|
|
7
15
|
Add the plugin to your Vite configuration:
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { join } from "node:path";
|
|
8
8
|
import { readFileSync } from "node:fs";
|
|
9
|
+
import { createHash } from "node:crypto";
|
|
9
10
|
// constants ==================================================================
|
|
10
11
|
export const PROJECT_NAME = "@open-xchange/vite-plugin-project-meta";
|
|
11
12
|
// plugin =====================================================================
|
|
@@ -45,5 +46,19 @@ export default function vitePluginProjectMeta(options) {
|
|
|
45
46
|
const code = `export default ${JSON.stringify(metadata)};`;
|
|
46
47
|
return { code, map: { mappings: "" } };
|
|
47
48
|
},
|
|
49
|
+
transformIndexHtml(_html, context) {
|
|
50
|
+
if (!context.bundle) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const hash = createHash("md5").update(metadata.builddate).digest("hex");
|
|
54
|
+
const len = Number.parseInt(hash.slice(0, 4), 16) % 99 + 42;
|
|
55
|
+
const count = Math.ceil(len / hash.length);
|
|
56
|
+
const content = hash.repeat(count).slice(0, len);
|
|
57
|
+
return [{
|
|
58
|
+
tag: "meta",
|
|
59
|
+
attrs: { name: "etag-fix", content },
|
|
60
|
+
injectTo: "head",
|
|
61
|
+
}];
|
|
62
|
+
},
|
|
48
63
|
};
|
|
49
64
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-xchange/vite-plugin-project-meta",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Vite plugin providing a virtual import for project metadata",
|
|
5
5
|
"repository": {
|
|
6
6
|
"url": "https://gitlab.open-xchange.com/fspd/npm-packages/vite-plugin-project-meta"
|