vite-plugin-inline-multipage 1.0.5 → 1.0.6

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/package.json CHANGED
@@ -1,9 +1,19 @@
1
1
  {
2
2
  "name": "vite-plugin-inline-multipage",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "A Vite plugin that inlines multi-paged applications (like in svelte) to multiple html files",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "exports": {
11
+ ".": {
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.js",
14
+ "types": "./dist/index.d.ts"
15
+ }
16
+ },
7
17
  "scripts": {
8
18
  "build": "tsc",
9
19
  "prepublishOnly": "npm run build"
package/src/index.ts DELETED
@@ -1,95 +0,0 @@
1
- import { type Plugin } from 'vite';
2
- import glob from 'tiny-glob';
3
- import path from 'path';
4
- import fs from 'fs';
5
- import * as cheerio from 'cheerio';
6
-
7
- export interface InlineEverythingOptions {
8
- /**
9
- * Dir where the build files are located (default: 'build')
10
- */
11
- buildDir?: string;
12
-
13
- /**
14
- * If the plugin should remove the _app directory after inlining (default: true)
15
- */
16
- cleanUp?: boolean;
17
- }
18
-
19
- export default function inlineEverythingPlugin(options?: InlineEverythingOptions): Plugin {
20
- const {
21
- buildDir = 'build',
22
- cleanUp = true
23
- } = options || {};
24
-
25
- return {
26
- name: 'inline-everything',
27
- apply: 'build',
28
- closeBundle: async () => {
29
- const resolvedBuildDir = path.resolve(process.cwd(), buildDir);
30
- const htmlFiles = await glob('**/*.html', {
31
- cwd: resolvedBuildDir,
32
- absolute: true
33
- });
34
-
35
- const assetFiles = await glob('**/_app/immutable/**/*.{css,js}', {
36
- cwd: resolvedBuildDir,
37
- absolute: true
38
- });
39
-
40
- const assetMap = new Map();
41
- assetFiles.forEach(file => {
42
- assetMap.set(path.basename(file), file);
43
- });
44
-
45
- for (const htmlFile of htmlFiles) {
46
- let html = fs.readFileSync(htmlFile, 'utf8');
47
- const load_html = cheerio.load(html);
48
-
49
- load_html('link[rel="stylesheet"]').each((i, el) => {
50
- const href = load_html(el).attr('href');
51
- if (href) {
52
- const filename = path.basename(href);
53
- if (assetMap.has(filename)) {
54
- try {
55
- const cssContent = fs.readFileSync(assetMap.get(filename), 'utf8');
56
- load_html(el).replaceWith(`<style>${cssContent}</style>`);
57
- } catch (e) {
58
- console.warn(`Failed to inline CSS ${filename}:`, (e as Error).message);
59
- }
60
- }
61
- }
62
- });
63
-
64
- load_html('script[type="module"][src]').each((i, el) => {
65
- const src = load_html(el).attr('src');
66
- if (src) {
67
- const filename = path.basename(src);
68
- if (assetMap.has(filename)) {
69
- try {
70
- const jsContent = fs.readFileSync(assetMap.get(filename), 'utf8');
71
- load_html(el).replaceWith(`<script type="module">${jsContent}</script>`);
72
- } catch (e) {
73
- console.warn(`Failed to inline JS ${filename}:`, (e as Error).message);
74
- }
75
- }
76
- }
77
- });
78
-
79
- load_html('link[rel="modulepreload"]').remove();
80
- load_html('link[rel="preload"]').remove();
81
- load_html('script[data-sveltekit-hydrate]').remove();
82
-
83
- fs.writeFileSync(htmlFile, load_html.html());
84
- }
85
-
86
- if (cleanUp) {
87
- try {
88
- fs.rmSync(path.join(resolvedBuildDir, '_app'), { recursive: true });
89
- } catch (e) {
90
- console.warn('Could not clean up _app directory:', (e as Error).message);
91
- }
92
- }
93
- }
94
- };
95
- }
package/tsconfig.json DELETED
@@ -1,15 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ESNext",
4
- "module": "CommonJS",
5
- "declaration": true,
6
- "outDir": "./dist",
7
- "strict": true,
8
- "esModuleInterop": true,
9
- "skipLibCheck": true,
10
- "forceConsistentCasingInFileNames": true,
11
- "rootDir": "./src"
12
- },
13
- "include": ["src/**/*"],
14
- "exclude": ["node_modules"]
15
- }