-
Notifications
You must be signed in to change notification settings - Fork 0
/
svelte.config.js
96 lines (90 loc) · 2.37 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
import adapter from '@sveltejs/adapter-static';
import autoprefixer from 'autoprefixer';
import fs from 'fs-extra';
import md from 'mdsvex';
import mdsvexConfig from './mdsvex.config.js';
import sveltePreprocess from 'svelte-preprocess';
import url from 'url';
const getRootRelativePath = (homepageURL) => {
if (!homepageURL) return '';
const page = new url.URL(homepageURL);
return homepageURL
.replace(`${page.protocol}//${page.host}`, '')
.replace(/\/$/, '');
};
const prod = process.env.NODE_ENV === 'production';
const pkg = fs.readJSONSync(new URL('./package.json', import.meta.url));
if (prod && !pkg.homepage)
throw new Error(
'Need to fill out the homepage in package.json before building!'
);
const homepage = prod ? pkg.homepage.replace(/\/$/, '') : '';
process.env.VITE_DATELINE = new Date().toISOString();
export default {
extensions: ['.svelte', ...mdsvexConfig.extensions],
preprocess: [
md.mdsvex(mdsvexConfig),
sveltePreprocess({
preserve: ['ld+json'],
scss: {
includePaths: ['src/', 'node_modules/bootstrap/scss/'],
importer: [
(url) => {
// Redirect tilde-prefixed imports to node_modules
if (/^~/.test(url))
return { file: `node_modules/${url.replace('~', '')}` };
return null;
},
],
quietDeps: true,
},
postcss: {
plugins: [autoprefixer],
},
}),
],
kit: {
appDir: 'app',
paths: {
assets: prod ? homepage + '/cdn' : '',
base: prod ? getRootRelativePath(homepage) : '',
},
prerender: { default: true, onError: 'continue' },
trailingSlash: 'always',
adapter: adapter({
pages: 'docs',
assets: 'docs/cdn',
fallback: null,
}),
files: {
assets: 'src/statics',
lib: 'src/lib',
routes: 'src/routes',
template: 'src/template.html',
},
vite: {
build: { target: 'es2015' },
server: {
fs: {
allow: ['.'],
},
},
resolve: {
alias: {
$utils: '/src/utils',
$pkg: '/package.json',
},
},
optimizeDeps: {
exclude: ['svelte-fa', '@reuters-graphics/style-theme-eisbaer'],
include: [
'marked',
'lodash-es',
'pym.js',
'classnames',
'ua-parser-js',
],
},
},
},
};