-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile.ts
44 lines (37 loc) · 1.3 KB
/
compile.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import {ensureDir, readFileStr, writeFileStr} from 'https://deno.land/std@0.55.0/fs/mod.ts';
import {compile} from './svelte/compiler.mjs';
const svelteImportsPath = '../svelte';
//
// The goal is to make this work without having to install Svelte as a dependency like with Pika:
//
// import {compile} from 'https://cdn.pika.dev/svelte@^3.23.0';
// const sveltePath = 'https://cdn.pika.dev/svelte';
//
// This is not for now since there are some issues regarding imports, but it's an ideal...
const sourceName = 'Deno.svelte';
const source = await readFileStr(`src/${sourceName}`);
const compiledSsr = compile(source, {
filename: sourceName,
generate: 'ssr',
name: '_'+sourceName.replace('.svelte', '')+'Component',
sveltePath: svelteImportsPath,
});
const compiledDom = compile(source, {
filename: sourceName,
generate: 'dom',
name: '_'+sourceName.replace('.svelte', '')+'Component',
sveltePath: svelteImportsPath,
});
const CSS = compiledSsr.css.code;
const JS_DOM = compiledDom.js.code;
/*
/!\ Dirty fix
*/
const JS_SSR = compiledSsr.js.code.replace(
'"../svelte/internal"',
'"../svelte/internal/index.mjs"'
);
await ensureDir('output/');
await writeFileStr(`output/${sourceName}.css`, CSS);
await writeFileStr(`output/${sourceName}.ssr.ts`, JS_SSR);
await writeFileStr(`output/${sourceName}.dom.js`, JS_DOM);