-
Notifications
You must be signed in to change notification settings - Fork 1
/
svelte.config.js
69 lines (61 loc) · 1.97 KB
/
svelte.config.js
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import netlify from '@sveltejs/adapter-netlify';
import fs from 'fs';
import path from 'path';
import { string } from 'rollup-plugin-string';
const dev = process.env.NODE_ENV === 'development';
// https://github.com/rollup/rollup/issues/2463#issuecomment-455957865
// Basically, the function 'newsTargetVirtualModule' helps to import 'news-target'.
// 'news-target' is crucial for exporting all file names that are contained in the directory /news.
const newsTargetVirtualModule = () => ({
name: 'news-targets',
resolveId(id) {
return id === 'news-targets' ? id : null;
},
load(id) {
if (id === 'news-targets') {
const targetDir = path.join(path.resolve(), 'news');
const files = fs.readdirSync(targetDir);
const objectEntries = files.map(
(file) =>
` '${file}': () => import('${path.join(targetDir, file)}')`
);
return `export default {\n${objectEntries.join(',\n')}\n};`;
}
return null;
},
});
/** @type {import('@sveltejs/kit').Config} */
const config = {
// options passed to svelte.compile (https://svelte.dev/docs#svelte_compile)
compilerOptions: {
css: false,
hydratable: true,
dev,
},
// an array of file extensions that should be treated as Svelte components
extensions: ['.svelte'],
kit: {
adapter: netlify(),
target: '#svelte',
prerender: {
crawl: true,
enabled: true,
entries: ['*'],
},
vite: {
plugins: [
newsTargetVirtualModule(),
//@ts-ignore
string({
include: '**/*.txt',
}),
],
optimizeDeps: {
include: ['fuzzy'],
},
},
},
// options passed to svelte.preprocess (https://svelte.dev/docs#svelte_preprocess)
preprocess: null,
};
export default config;