vite-plugin-sitemap-ts 0.1.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/LICENSE +21 -0
- package/README.md +35 -0
- package/dist/index.cjs +95 -0
- package/dist/index.d.cts +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +68 -0
- package/package.json +78 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Cornelius Weidmann
|
|
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
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# vite-plugin-sitemap-ts
|
|
2
|
+
|
|
3
|
+
A Vite plugin to generate `sitemap.xml`. Works in development mode by proxying middleware to `/sitemap.xml`.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -D vite-plugin-sitemap-ts
|
|
9
|
+
pnpm add -D vite-plugin-sitemap-ts
|
|
10
|
+
yarn add -D vite-plugin-sitemap-ts
|
|
11
|
+
bun add -D vite-plugin-sitemap-ts
|
|
12
|
+
deno add -D npm:vite-plugin-sitemap-ts
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
// vite.config.ts
|
|
19
|
+
import { sitemap } from 'vite-plugin-sitemap-ts'
|
|
20
|
+
|
|
21
|
+
export default {
|
|
22
|
+
plugins: [
|
|
23
|
+
sitemap(),
|
|
24
|
+
],
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Options
|
|
29
|
+
|
|
30
|
+
All options are optional.
|
|
31
|
+
|
|
32
|
+
| Option | Type | Default | Description |
|
|
33
|
+
|---------|------------------------------------|---------|------------------------------------------------------------------------------|
|
|
34
|
+
| enabled | *boolean* | `true` | Toggle the plugin on or off |
|
|
35
|
+
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
sitemap: () => sitemap
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
|
|
27
|
+
// src/utils.ts
|
|
28
|
+
var SITEMAP_CONTENT = `<?xml version="1.0" encoding="UTF-8"?>
|
|
29
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
30
|
+
</urlset>`;
|
|
31
|
+
var logColor = (color, text, bold = false) => {
|
|
32
|
+
const colorCode = {
|
|
33
|
+
red: bold ? "\x1B[1;31m" : "\x1B[31m",
|
|
34
|
+
green: bold ? "\x1B[1;32m" : "\x1B[32m",
|
|
35
|
+
yellow: bold ? "\x1B[1;33m" : "\x1B[33m"
|
|
36
|
+
};
|
|
37
|
+
return `${colorCode[color]}${text}${LOGGER_CLEAR}`;
|
|
38
|
+
};
|
|
39
|
+
var LOGGER_CLEAR = "\x1B[0m";
|
|
40
|
+
var LOGGER_PREFIX = logColor("yellow", "[sitemap-ts]", true);
|
|
41
|
+
var LOGGER_SUCCESS = logColor("green", "\u2713", true);
|
|
42
|
+
var LOGGER_FAILURE = logColor("red", "\u2717", true);
|
|
43
|
+
|
|
44
|
+
// src/plugin.ts
|
|
45
|
+
var BASE_PATH = "/";
|
|
46
|
+
var FILE_NAME = "sitemap.xml";
|
|
47
|
+
var SITEMAP_PATH = `${BASE_PATH}${FILE_NAME}`;
|
|
48
|
+
function sitemap(options = {}) {
|
|
49
|
+
let config;
|
|
50
|
+
let success = false;
|
|
51
|
+
const sitemapContent = SITEMAP_CONTENT;
|
|
52
|
+
const enabled = options.enabled ?? true;
|
|
53
|
+
return {
|
|
54
|
+
name: "vite-plugin-sitemap-ts",
|
|
55
|
+
apply: () => enabled,
|
|
56
|
+
configResolved(resolvedConfig) {
|
|
57
|
+
config = resolvedConfig;
|
|
58
|
+
},
|
|
59
|
+
configureServer(server) {
|
|
60
|
+
server.middlewares.use(SITEMAP_PATH, (_req, res) => {
|
|
61
|
+
res.setHeader("Content-Type", "text/xml; charset=utf-8");
|
|
62
|
+
res.end(sitemapContent);
|
|
63
|
+
});
|
|
64
|
+
config.logger.info(
|
|
65
|
+
`${LOGGER_CLEAR}${LOGGER_SUCCESS} ${LOGGER_PREFIX} Exposed new route: ${logColor("green", SITEMAP_PATH)}`
|
|
66
|
+
);
|
|
67
|
+
},
|
|
68
|
+
generateBundle() {
|
|
69
|
+
if (this.environment?.name && this.environment.name !== "client") {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
config.logger.info(
|
|
73
|
+
`
|
|
74
|
+
- ${LOGGER_CLEAR}${LOGGER_PREFIX} Writing sitemap.xml at ${config.build.outDir}${SITEMAP_PATH}`
|
|
75
|
+
);
|
|
76
|
+
try {
|
|
77
|
+
this.emitFile({
|
|
78
|
+
type: "asset",
|
|
79
|
+
fileName: FILE_NAME,
|
|
80
|
+
source: sitemapContent
|
|
81
|
+
});
|
|
82
|
+
success = true;
|
|
83
|
+
} catch (_err) {
|
|
84
|
+
success = false;
|
|
85
|
+
}
|
|
86
|
+
config.logger.info(
|
|
87
|
+
`${LOGGER_CLEAR}${success ? LOGGER_SUCCESS : LOGGER_FAILURE} ${LOGGER_PREFIX} ${success ? `Success` : `Failed writing sitemap.xml!`}`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
93
|
+
0 && (module.exports = {
|
|
94
|
+
sitemap
|
|
95
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
type Options = {
|
|
4
|
+
/**
|
|
5
|
+
* Toggle the plugin on or off. Useful if you want to disable the plugin, e.g. in development mode.
|
|
6
|
+
*
|
|
7
|
+
* **Default: `true`**
|
|
8
|
+
*/
|
|
9
|
+
enabled?: boolean;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
declare function sitemap(options?: Options): Plugin;
|
|
13
|
+
|
|
14
|
+
export { type Options, sitemap };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
type Options = {
|
|
4
|
+
/**
|
|
5
|
+
* Toggle the plugin on or off. Useful if you want to disable the plugin, e.g. in development mode.
|
|
6
|
+
*
|
|
7
|
+
* **Default: `true`**
|
|
8
|
+
*/
|
|
9
|
+
enabled?: boolean;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
declare function sitemap(options?: Options): Plugin;
|
|
13
|
+
|
|
14
|
+
export { type Options, sitemap };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// src/utils.ts
|
|
2
|
+
var SITEMAP_CONTENT = `<?xml version="1.0" encoding="UTF-8"?>
|
|
3
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
4
|
+
</urlset>`;
|
|
5
|
+
var logColor = (color, text, bold = false) => {
|
|
6
|
+
const colorCode = {
|
|
7
|
+
red: bold ? "\x1B[1;31m" : "\x1B[31m",
|
|
8
|
+
green: bold ? "\x1B[1;32m" : "\x1B[32m",
|
|
9
|
+
yellow: bold ? "\x1B[1;33m" : "\x1B[33m"
|
|
10
|
+
};
|
|
11
|
+
return `${colorCode[color]}${text}${LOGGER_CLEAR}`;
|
|
12
|
+
};
|
|
13
|
+
var LOGGER_CLEAR = "\x1B[0m";
|
|
14
|
+
var LOGGER_PREFIX = logColor("yellow", "[sitemap-ts]", true);
|
|
15
|
+
var LOGGER_SUCCESS = logColor("green", "\u2713", true);
|
|
16
|
+
var LOGGER_FAILURE = logColor("red", "\u2717", true);
|
|
17
|
+
|
|
18
|
+
// src/plugin.ts
|
|
19
|
+
var BASE_PATH = "/";
|
|
20
|
+
var FILE_NAME = "sitemap.xml";
|
|
21
|
+
var SITEMAP_PATH = `${BASE_PATH}${FILE_NAME}`;
|
|
22
|
+
function sitemap(options = {}) {
|
|
23
|
+
let config;
|
|
24
|
+
let success = false;
|
|
25
|
+
const sitemapContent = SITEMAP_CONTENT;
|
|
26
|
+
const enabled = options.enabled ?? true;
|
|
27
|
+
return {
|
|
28
|
+
name: "vite-plugin-sitemap-ts",
|
|
29
|
+
apply: () => enabled,
|
|
30
|
+
configResolved(resolvedConfig) {
|
|
31
|
+
config = resolvedConfig;
|
|
32
|
+
},
|
|
33
|
+
configureServer(server) {
|
|
34
|
+
server.middlewares.use(SITEMAP_PATH, (_req, res) => {
|
|
35
|
+
res.setHeader("Content-Type", "text/xml; charset=utf-8");
|
|
36
|
+
res.end(sitemapContent);
|
|
37
|
+
});
|
|
38
|
+
config.logger.info(
|
|
39
|
+
`${LOGGER_CLEAR}${LOGGER_SUCCESS} ${LOGGER_PREFIX} Exposed new route: ${logColor("green", SITEMAP_PATH)}`
|
|
40
|
+
);
|
|
41
|
+
},
|
|
42
|
+
generateBundle() {
|
|
43
|
+
if (this.environment?.name && this.environment.name !== "client") {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
config.logger.info(
|
|
47
|
+
`
|
|
48
|
+
- ${LOGGER_CLEAR}${LOGGER_PREFIX} Writing sitemap.xml at ${config.build.outDir}${SITEMAP_PATH}`
|
|
49
|
+
);
|
|
50
|
+
try {
|
|
51
|
+
this.emitFile({
|
|
52
|
+
type: "asset",
|
|
53
|
+
fileName: FILE_NAME,
|
|
54
|
+
source: sitemapContent
|
|
55
|
+
});
|
|
56
|
+
success = true;
|
|
57
|
+
} catch (_err) {
|
|
58
|
+
success = false;
|
|
59
|
+
}
|
|
60
|
+
config.logger.info(
|
|
61
|
+
`${LOGGER_CLEAR}${success ? LOGGER_SUCCESS : LOGGER_FAILURE} ${LOGGER_PREFIX} ${success ? `Success` : `Failed writing sitemap.xml!`}`
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export {
|
|
67
|
+
sitemap
|
|
68
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vite-plugin-sitemap-ts",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Vite plugin to generate sitemap.xml. Works in dev mode.",
|
|
5
|
+
"author": "Cornelius Weidmann <cornelius@kyco.io> (https://kyco.io)",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"main": "./dist/index.cjs",
|
|
10
|
+
"module": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"require": {
|
|
19
|
+
"types": "./dist/index.d.cts",
|
|
20
|
+
"default": "./dist/index.cjs"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"provenance": true
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"vite",
|
|
32
|
+
"vite-plugin",
|
|
33
|
+
"sitemap",
|
|
34
|
+
"sitemap.xml",
|
|
35
|
+
"typescript"
|
|
36
|
+
],
|
|
37
|
+
"homepage": "https://github.com/kyco/vite-plugin-sitemap-ts",
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git+https://github.com/kyco/vite-plugin-sitemap-ts.git"
|
|
41
|
+
},
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/kyco/vite-plugin-sitemap-ts/issues"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsup",
|
|
47
|
+
"lint": "biome check .",
|
|
48
|
+
"lint:fix": "biome check --write .",
|
|
49
|
+
"test": "vitest run",
|
|
50
|
+
"test:watch": "vitest",
|
|
51
|
+
"prepublishOnly": "tsup",
|
|
52
|
+
"demo:dev": "pnpm --filter basic dev",
|
|
53
|
+
"demo:build": "pnpm --filter basic build",
|
|
54
|
+
"demo:preview": "pnpm --filter basic preview",
|
|
55
|
+
"demo:tanstack:dev": "pnpm --filter tanstack dev",
|
|
56
|
+
"demo:tanstack:build": "pnpm --filter tanstack build",
|
|
57
|
+
"demo:tanstack:preview": "pnpm --filter tanstack preview",
|
|
58
|
+
"clean": "rm -rf dist node_modules demo/*/dist demo/*/node_modules",
|
|
59
|
+
"update-packages": "pnpm dlx npm-check-updates --format group -i"
|
|
60
|
+
},
|
|
61
|
+
"packageManager": "pnpm@10.32.1",
|
|
62
|
+
"peerDependencies": {
|
|
63
|
+
"vite": ">=2"
|
|
64
|
+
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"@biomejs/biome": "^2.4.6",
|
|
67
|
+
"@semantic-release/changelog": "^6.0.3",
|
|
68
|
+
"@semantic-release/git": "^10.0.1",
|
|
69
|
+
"@semantic-release/github": "^12.0.6",
|
|
70
|
+
"@semantic-release/npm": "^13.1.5",
|
|
71
|
+
"conventional-changelog-conventionalcommits": "^9.3.0",
|
|
72
|
+
"semantic-release": "^25.0.3",
|
|
73
|
+
"tsup": "^8.5.1",
|
|
74
|
+
"typescript": "^5.9.3",
|
|
75
|
+
"vite": "^7.3.1",
|
|
76
|
+
"vitest": "^4.1.0"
|
|
77
|
+
}
|
|
78
|
+
}
|