-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathsvelte.config.js
98 lines (84 loc) · 2.68 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/* jshint esversion: 9 */
// command env properties
const hasAdapter = process.env.ADAPTER;
const adapt = hasAdapter ? hasAdapter : 'node';
// Imports
import { mdsvex } from 'mdsvex';
import mdsvexConfig from './mdsvex.config.js';
import preprocess from 'svelte-preprocess';
import { resolve } from 'path';
import { dirname } from 'path';
import { fileURLToPath } from 'url';
// import { createRequire } from 'module';
// Adapters
import staticAdapter from '@sveltejs/adapter-static';
import nodeAdapter from '@sveltejs/adapter-node';
import netlifyAdapter from '@sveltejs/adapter-netlify';
import vercelAdapter from '@sveltejs/adapter-vercel';
// Custom require function as replacement for the require from the commonJS in ES Module
// const customRequire = createRequire(import.meta.url); // jshint ignore:line
// Custom __dirname as replacement for the __dirname from the commonJS in ES Module
const __dirname = dirname(fileURLToPath(import.meta.url)); // jshint ignore:line
// const pkg = customRequire('./package.json');
const options = JSON.stringify(process.env.OPTIONS || '{}');
const getAdapters = (adapt) => {
switch (adapt) {
case 'node':
return nodeAdapter;
case 'static':
return staticAdapter;
case 'netlify':
return netlifyAdapter;
case 'vercel':
return vercelAdapter;
default:
return nodeAdapter;
}
};
const adapter = getAdapters(adapt);
/** @type {import('@sveltejs/kit').Config} */
const config = {
extensions: ['.svelte', ...mdsvexConfig.extensions],
// Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors
preprocess: [
preprocess({
postcss: true,
preserve: ['ld+json'],
}),
mdsvex(mdsvexConfig),
],
kit: {
// hydrate the <div id="svelte"> element in src/app.html
target: '#sveltekit-blog',
ssr: true,
prerender: {
crawl: true,
enabled: true,
onError: 'fail',
entries: ['*'],
},
vite: () => ({
resolve: {
alias: {
$stores: resolve(__dirname, './src/stores'),
$components: resolve(__dirname, './src/lib/shared/components'),
$ui: resolve(__dirname, './src/lib/shared/ui'),
$layouts: resolve(__dirname, './src/lib/layouts'),
$shared: resolve(__dirname, './src/lib/shared'),
$models: resolve(__dirname, './src/lib/models'),
$data: resolve(__dirname, './src/lib/data'),
$core: resolve(__dirname, './src/lib/core'),
$utils: resolve(__dirname, './src/lib/utils'),
$environment: resolve(__dirname, './src/environments'),
},
},
envPrefix: ['VITE_', 'SVELTEKIT_BLOG_'],
}),
},
};
if (hasAdapter) {
config.kit.adapter = adapter(options);
}
export default config;