astro-strip-whitespace 0.2.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 SegaraRai
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,53 @@
1
+ # astro-strip-whitespace
2
+
3
+ Astro integration that strips inter-node whitespace in `.astro` and `.svelte` templates _before_ compilation.
4
+
5
+ Under the hood, this prepends the Vite plugin from [`unplugin-strip-whitespace`](../unplugin-strip-whitespace) in `astro:config:done` so it runs early.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ astro add astro-strip-whitespace
11
+
12
+ # pnpm add -D astro-strip-whitespace
13
+ # npm i -D astro-strip-whitespace
14
+ # yarn add -D astro-strip-whitespace
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ In `astro.config.mjs` / `astro.config.ts`:
20
+
21
+ ```ts
22
+ import { defineConfig } from "astro/config";
23
+ import stripWhitespace from "astro-strip-whitespace";
24
+
25
+ export default defineConfig({
26
+ integrations: [stripWhitespace()],
27
+ });
28
+ ```
29
+
30
+ ### Options
31
+
32
+ The integration accepts the same options as `unplugin-strip-whitespace` (`StripWhitespaceOptions`). Common ones:
33
+
34
+ - `preserveBlankLines`: keep "section breaks" by skipping gaps that contain an empty line.
35
+ - `selectLanguage`: restrict processing to only Astro or only Svelte.
36
+ - `skipOnError`: skip transform on errors instead of failing the build.
37
+
38
+ Example: only process Astro files
39
+
40
+ ```ts
41
+ stripWhitespace({
42
+ selectLanguage: ["astro"],
43
+ });
44
+ ```
45
+
46
+ ## Notes
47
+
48
+ - If you also use Svelte via `@astrojs/svelte`, the integration can strip whitespace in `.svelte` files too (default behavior).
49
+ - This runs as a `pre` transform to avoid hydration mismatches that can happen when whitespace is removed only in the final HTML.
50
+
51
+ ## License
52
+
53
+ MIT
@@ -0,0 +1,8 @@
1
+ import { AstroIntegration } from "astro";
2
+ import { StripWhitespaceOptions } from "unplugin-strip-whitespace";
3
+
4
+ //#region src/index.d.ts
5
+ declare function astroStripWhitespace(options?: StripWhitespaceOptions): AstroIntegration;
6
+ //#endregion
7
+ export { astroStripWhitespace as default };
8
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;iBAIS,oBAAA,WACG,yBACT"}
package/dist/index.mjs ADDED
@@ -0,0 +1,18 @@
1
+ import viteStripWhitespace from "unplugin-strip-whitespace/vite";
2
+
3
+ //#region src/index.ts
4
+ function astroStripWhitespace(options) {
5
+ return {
6
+ name: "astro-strip-whitespace",
7
+ hooks: { "astro:config:done": ({ config }) => {
8
+ config.vite ??= {};
9
+ config.vite.plugins ??= [];
10
+ config.vite.plugins.unshift(viteStripWhitespace(options));
11
+ } }
12
+ };
13
+ }
14
+ var src_default = astroStripWhitespace;
15
+
16
+ //#endregion
17
+ export { src_default as default };
18
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { AstroIntegration } from \"astro\";\nimport type { StripWhitespaceOptions } from \"unplugin-strip-whitespace\";\nimport viteStripWhitespace from \"unplugin-strip-whitespace/vite\";\n\nfunction astroStripWhitespace(\n options?: StripWhitespaceOptions,\n): AstroIntegration {\n return {\n name: \"astro-strip-whitespace\",\n hooks: {\n \"astro:config:done\": ({ config }) => {\n config.vite ??= {};\n config.vite.plugins ??= [];\n config.vite.plugins.unshift(viteStripWhitespace(options));\n },\n },\n } satisfies AstroIntegration;\n}\n\nexport default astroStripWhitespace;\n"],"mappings":";;;AAIA,SAAS,qBACP,SACkB;AAClB,QAAO;EACL,MAAM;EACN,OAAO,EACL,sBAAsB,EAAE,aAAa;AACnC,UAAO,SAAS,EAAE;AAClB,UAAO,KAAK,YAAY,EAAE;AAC1B,UAAO,KAAK,QAAQ,QAAQ,oBAAoB,QAAQ,CAAC;KAE5D;EACF;;AAGH,kBAAe"}
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "astro-strip-whitespace",
3
+ "version": "0.2.0",
4
+ "description": "Astro integration that strips inter-node whitespace in Astro and Svelte templates.",
5
+ "license": "MIT",
6
+ "author": "SegaraRai",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/SegaraRai/strip-whitespace.git",
10
+ "directory": "packages/astro-strip-whitespace"
11
+ },
12
+ "homepage": "https://github.com/SegaraRai/strip-whitespace#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/SegaraRai/strip-whitespace/issues"
15
+ },
16
+ "keywords": [
17
+ "astro",
18
+ "astro-integration",
19
+ "svelte",
20
+ "whitespace",
21
+ "minify"
22
+ ],
23
+ "type": "module",
24
+ "sideEffects": false,
25
+ "main": "./dist/index.mjs",
26
+ "module": "./dist/index.mjs",
27
+ "types": "./dist/index.d.mts",
28
+ "exports": {
29
+ ".": "./dist/index.mjs",
30
+ "./package.json": "./package.json"
31
+ },
32
+ "files": [
33
+ "dist",
34
+ "README.md",
35
+ "LICENSE"
36
+ ],
37
+ "dependencies": {
38
+ "unplugin-strip-whitespace": "0.2.0"
39
+ },
40
+ "devDependencies": {
41
+ "@arethetypeswrong/core": "^0.18.2",
42
+ "@types/node": "^25.0.6",
43
+ "astro": "^5.16.8",
44
+ "prettier": "^3.7.4",
45
+ "prettier-plugin-organize-imports": "^4.3.0",
46
+ "tsdown": "^0.19.0",
47
+ "typescript": "^5.9.3",
48
+ "vitest": "^4.0.16",
49
+ "strip-whitespace-wasm": "0.1.0"
50
+ },
51
+ "peerDependencies": {
52
+ "astro": ">=5.0.0"
53
+ },
54
+ "scripts": {
55
+ "build": "tsdown",
56
+ "test": "vitest run"
57
+ }
58
+ }