svelte-bundle 0.0.21 → 0.0.23
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/ReadMe.md +4 -3
- package/bundle.js +25 -9
- package/cli.js +11 -0
- package/package.json +2 -2
package/ReadMe.md
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
> ⚠️ **NOTICE:** While this tool is currently functional, it has not nearly been battle-tested enough to ensure it works in most use-cases.
|
|
2
|
+
|
|
1
3
|
## Usage
|
|
2
4
|
This tool can be used with `npx`:
|
|
3
5
|
```bash
|
|
4
6
|
npx svelte-bundle -i <input-dir> -o <output-dir>
|
|
5
7
|
```
|
|
8
|
+
### Full Documentation: [https://github.com/uhteddy/svelte-bundle/wiki](https://github.com/uhteddy/svelte-bundle/wiki)
|
|
6
9
|
|
|
7
10
|
# Svelte Bundle CLI
|
|
8
11
|
|
|
@@ -12,9 +15,7 @@ Just note, the purpose of this tool is **NOT** to bundle an entire Svelte app, i
|
|
|
12
15
|
|
|
13
16
|
Utilizing this you will be able to develop a page with the joy of svelte and be able to directly get a single `.html` file that you can utilize getting full use-case of svelte.
|
|
14
17
|
|
|
15
|
-
⚠️ **Note**: This tool is **NOT** made to function with SvelteKit, this takes a single `.svelte` file as input and
|
|
16
|
-
|
|
17
|
-
⚠️ **Note**: This tool is currently in early development and is not fully complete. The roadmap and additional features will be added over time. There is currently **NO** testing on this, meaning there is no guarentee it will work for most usecases.
|
|
18
|
+
⚠️ **Note**: This tool is **NOT** made to function with SvelteKit natively, this takes a single `.svelte` file as input and will output a single `.html` file.
|
|
18
19
|
|
|
19
20
|
## Inspiration
|
|
20
21
|
This tool was inspired by the need I had when it came to updating the CMS for a company I worked for. They were looking for more custom content on their website which used an outdated CMS. Pages were only able to include HTML, CSS, and JS.
|
package/bundle.js
CHANGED
|
@@ -11,6 +11,12 @@ import postcss from 'postcss';
|
|
|
11
11
|
import tailwindcss from 'tailwindcss';
|
|
12
12
|
import autoprefixer from 'autoprefixer';
|
|
13
13
|
import cssnano from 'cssnano';
|
|
14
|
+
import { fileURLToPath } from 'url';
|
|
15
|
+
import { createRequire } from 'module';
|
|
16
|
+
|
|
17
|
+
const require = createRequire(import.meta.url);
|
|
18
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
19
|
+
const __dirname = path.dirname(__filename);
|
|
14
20
|
|
|
15
21
|
export async function buildStaticFile(svelteFilePath, outputDir, options = {}) {
|
|
16
22
|
const { useTailwind = false, tailwindConfig = null } = options;
|
|
@@ -62,6 +68,9 @@ export async function buildStaticFile(svelteFilePath, outputDir, options = {}) {
|
|
|
62
68
|
.process(tailwindCss, { from: undefined });
|
|
63
69
|
globalCssText = processedCss.css;
|
|
64
70
|
}
|
|
71
|
+
|
|
72
|
+
// Get the absolute path to svelte/internal
|
|
73
|
+
const svelteInternalPath = require.resolve('svelte/internal');
|
|
65
74
|
|
|
66
75
|
// Create temporary SSR bundle
|
|
67
76
|
const ssrBundle = await rollup({
|
|
@@ -90,27 +99,32 @@ export async function buildStaticFile(svelteFilePath, outputDir, options = {}) {
|
|
|
90
99
|
}),
|
|
91
100
|
resolve({
|
|
92
101
|
browser: true,
|
|
93
|
-
dedupe: ['svelte']
|
|
102
|
+
dedupe: ['svelte'],
|
|
103
|
+
modulePaths: [path.join(__dirname, 'node_modules')],
|
|
104
|
+
rootDir: __dirname
|
|
94
105
|
}),
|
|
95
106
|
commonjs()
|
|
96
107
|
],
|
|
97
108
|
external: ['svelte/internal']
|
|
98
109
|
});
|
|
99
110
|
|
|
100
|
-
// Create a temporary directory
|
|
101
|
-
const tempDir = path.join(
|
|
111
|
+
// Create a temporary directory in the CLI package directory
|
|
112
|
+
const tempDir = path.join(__dirname, '.temp');
|
|
102
113
|
await fs.mkdir(tempDir, { recursive: true });
|
|
103
114
|
const tempSSRFile = path.join(tempDir, 'ssr-bundle.js');
|
|
104
115
|
|
|
105
|
-
// Generate SSR bundle
|
|
116
|
+
// Generate SSR bundle as ESM
|
|
106
117
|
await ssrBundle.write({
|
|
107
118
|
file: tempSSRFile,
|
|
108
119
|
format: 'es',
|
|
109
|
-
exports: 'default'
|
|
120
|
+
exports: 'default',
|
|
121
|
+
paths: {
|
|
122
|
+
'svelte/internal': svelteInternalPath
|
|
123
|
+
}
|
|
110
124
|
});
|
|
111
125
|
|
|
112
|
-
// Import the SSR bundle
|
|
113
|
-
const { default: App } = await import(tempSSRFile);
|
|
126
|
+
// Import the SSR bundle using dynamic import
|
|
127
|
+
const { default: App } = await import(/* @vite-ignore */`file://${tempSSRFile}`);
|
|
114
128
|
const { html: initialHtml } = App.render();
|
|
115
129
|
|
|
116
130
|
// Clean up temp files
|
|
@@ -142,7 +156,9 @@ export async function buildStaticFile(svelteFilePath, outputDir, options = {}) {
|
|
|
142
156
|
}),
|
|
143
157
|
resolve({
|
|
144
158
|
browser: true,
|
|
145
|
-
dedupe: ['svelte']
|
|
159
|
+
dedupe: ['svelte'],
|
|
160
|
+
modulePaths: [path.join(__dirname, 'node_modules')],
|
|
161
|
+
rootDir: __dirname
|
|
146
162
|
}),
|
|
147
163
|
commonjs(),
|
|
148
164
|
terser()
|
|
@@ -158,7 +174,7 @@ export async function buildStaticFile(svelteFilePath, outputDir, options = {}) {
|
|
|
158
174
|
});
|
|
159
175
|
|
|
160
176
|
// Create the final HTML
|
|
161
|
-
const finalHtml = `<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Static Svelte App</title><style>${globalCssText}${cssText}</style></head><body><div id="app">${initialHtml}</div><script
|
|
177
|
+
const finalHtml = `<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Static Svelte App</title><style>${globalCssText}${cssText}</style></head><body><div id="app">${initialHtml}</div><script>${clientCode}const app=new App({target:document.getElementById("app"),hydrate:!0});</script></body></html>`;
|
|
162
178
|
|
|
163
179
|
// Write the output file
|
|
164
180
|
const outputPath = path.join(outputDir, 'output.html');
|
package/cli.js
CHANGED
|
@@ -26,6 +26,14 @@ const rl = createInterface({
|
|
|
26
26
|
|
|
27
27
|
const question = (query) => new Promise((resolve) => rl.question(query, resolve));
|
|
28
28
|
|
|
29
|
+
// Add check for node version
|
|
30
|
+
const nodeVersion = process.versions.node;
|
|
31
|
+
const [major] = nodeVersion.split('.').map(Number);
|
|
32
|
+
if (major < 18) {
|
|
33
|
+
console.error(chalk.red(`Error: Node.js version 18 or higher is required. Current version: ${nodeVersion}`));
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
|
|
29
37
|
program
|
|
30
38
|
.name('svelte-bundle')
|
|
31
39
|
.description(packageJson.description)
|
|
@@ -132,6 +140,9 @@ async function validateAndProcess() {
|
|
|
132
140
|
} catch (error) {
|
|
133
141
|
console.error(chalk.red('\nBuild failed:'));
|
|
134
142
|
console.error(chalk.red(error.message));
|
|
143
|
+
if (error.stack) {
|
|
144
|
+
console.error(chalk.gray(error.stack));
|
|
145
|
+
}
|
|
135
146
|
process.exit(1);
|
|
136
147
|
} finally {
|
|
137
148
|
rl.close();
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-bundle",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.23",
|
|
4
4
|
"description": "Bundle Svelte files into static HTML files",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
|
-
"svelte-bundle": "
|
|
7
|
+
"svelte-bundle": "cli.js"
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
10
|
"cli.js",
|