-
Notifications
You must be signed in to change notification settings - Fork 0
/
svelte.config.js
86 lines (75 loc) · 2.5 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
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/* jshint esversion: 9 */
// command env properties
const hasAdapter = process.env.ADAPTER;
const adapt = hasAdapter ? hasAdapter : 'vercel';
const isAMP = process.env.AMP ? true : false;
import { imagetools } from 'vite-imagetools';
import { mdsvex } from 'mdsvex';
import preprocess from 'svelte-preprocess';
import vercelAdapter from '@sveltejs/adapter-vercel';
import nodeAdapter from '@sveltejs/adapter-node';
import staticAdapter from '@sveltejs/adapter-static';
import { resolve } from 'path';
import { dirname } from 'path';
import { fileURLToPath } from 'url';
// Custom require function as replacement for the require from the commonJS in ES Module
// Custom __dirname as replacement for the __dirname from the commonJS in ES Module
const __dirname = dirname(fileURLToPath(
import.meta.url)); // jshint ignore:line
const options = JSON.stringify(process.env.OPTIONS || '{}');
const getAdapters = (adapt) => {
switch (adapt) {
case 'node':
return nodeAdapter;
case 'static':
return staticAdapter;
case 'vercel':
return vercelAdapter;
default:
return nodeAdapter;
}
};
const adapter = getAdapters(adapt);
const extensions = [`.svelte`, '.svx'];
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors
preprocess: [
preprocess({
postcss: true,
sass: true,
scss: {
// prependData: `@import 'src/styles/variables/index.scss';`,
outputStyle: 'compressed',
},
preserve: ['ld+json'],
}),
mdsvex({ extensions: extensions }),
],
kit: {
adapter: vercelAdapter(),
vite: () => ({
resolve: {
alias: {
$hooks: resolve(__dirname, './src/hooks'),
$components: resolve(__dirname, './src/components'),
$lib: resolve(__dirname, './src/lib'),
$stores: resolve(__dirname, './src/lib/stores'),
}
},
plugins: [imagetools({ force: true })],
})
}
};
if (hasAdapter) {
config.kit.adapter = adapter(options);
}
if (config.kit.adapter.name === '@sveltejs/adapter-static') {
config.kit.prerender = {
crawl: true,
enabled: true
};
}
export default config;