vite-plugin-inline-multipage 1.0.6 → 1.0.8
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/dist/index.js +16 -55
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -1,75 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.default = inlineEverythingPlugin;
|
|
40
|
-
const tiny_glob_1 = __importDefault(require("tiny-glob"));
|
|
41
|
-
const path_1 = __importDefault(require("path"));
|
|
42
|
-
const fs_1 = __importDefault(require("fs"));
|
|
43
|
-
const cheerio = __importStar(require("cheerio"));
|
|
44
|
-
function inlineEverythingPlugin(options) {
|
|
1
|
+
import glob from 'tiny-glob';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import * as cheerio from 'cheerio';
|
|
5
|
+
export default function inlineEverythingPlugin(options) {
|
|
45
6
|
const { buildDir = 'build', cleanUp = true } = options || {};
|
|
46
7
|
return {
|
|
47
8
|
name: 'inline-everything',
|
|
48
9
|
apply: 'build',
|
|
49
10
|
closeBundle: async () => {
|
|
50
|
-
const resolvedBuildDir =
|
|
51
|
-
const htmlFiles = await (
|
|
11
|
+
const resolvedBuildDir = path.resolve(process.cwd(), buildDir);
|
|
12
|
+
const htmlFiles = await glob('**/*.html', {
|
|
52
13
|
cwd: resolvedBuildDir,
|
|
53
14
|
absolute: true
|
|
54
15
|
});
|
|
55
|
-
const assetFiles = await (
|
|
16
|
+
const assetFiles = await glob('**/_app/immutable/**/*.{css,js}', {
|
|
56
17
|
cwd: resolvedBuildDir,
|
|
57
18
|
absolute: true
|
|
58
19
|
});
|
|
59
20
|
const assetMap = new Map();
|
|
60
21
|
assetFiles.forEach(file => {
|
|
61
|
-
assetMap.set(
|
|
22
|
+
assetMap.set(path.basename(file), file);
|
|
62
23
|
});
|
|
63
24
|
for (const htmlFile of htmlFiles) {
|
|
64
|
-
let html =
|
|
25
|
+
let html = fs.readFileSync(htmlFile, 'utf8');
|
|
65
26
|
const load_html = cheerio.load(html);
|
|
66
27
|
load_html('link[rel="stylesheet"]').each((i, el) => {
|
|
67
28
|
const href = load_html(el).attr('href');
|
|
68
29
|
if (href) {
|
|
69
|
-
const filename =
|
|
30
|
+
const filename = path.basename(href);
|
|
70
31
|
if (assetMap.has(filename)) {
|
|
71
32
|
try {
|
|
72
|
-
const cssContent =
|
|
33
|
+
const cssContent = fs.readFileSync(assetMap.get(filename), 'utf8');
|
|
73
34
|
load_html(el).replaceWith(`<style>${cssContent}</style>`);
|
|
74
35
|
}
|
|
75
36
|
catch (e) {
|
|
@@ -81,10 +42,10 @@ function inlineEverythingPlugin(options) {
|
|
|
81
42
|
load_html('script[type="module"][src]').each((i, el) => {
|
|
82
43
|
const src = load_html(el).attr('src');
|
|
83
44
|
if (src) {
|
|
84
|
-
const filename =
|
|
45
|
+
const filename = path.basename(src);
|
|
85
46
|
if (assetMap.has(filename)) {
|
|
86
47
|
try {
|
|
87
|
-
const jsContent =
|
|
48
|
+
const jsContent = fs.readFileSync(assetMap.get(filename), 'utf8');
|
|
88
49
|
load_html(el).replaceWith(`<script type="module">${jsContent}</script>`);
|
|
89
50
|
}
|
|
90
51
|
catch (e) {
|
|
@@ -96,11 +57,11 @@ function inlineEverythingPlugin(options) {
|
|
|
96
57
|
load_html('link[rel="modulepreload"]').remove();
|
|
97
58
|
load_html('link[rel="preload"]').remove();
|
|
98
59
|
load_html('script[data-sveltekit-hydrate]').remove();
|
|
99
|
-
|
|
60
|
+
fs.writeFileSync(htmlFile, load_html.html());
|
|
100
61
|
}
|
|
101
62
|
if (cleanUp) {
|
|
102
63
|
try {
|
|
103
|
-
|
|
64
|
+
fs.rmSync(path.join(resolvedBuildDir, '_app'), { recursive: true });
|
|
104
65
|
}
|
|
105
66
|
catch (e) {
|
|
106
67
|
console.warn('Could not clean up _app directory:', e.message);
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-inline-multipage",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
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
|
+
"type": "module",
|
|
7
8
|
"files": [
|
|
8
9
|
"dist"
|
|
9
10
|
],
|