-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
143 lines (138 loc) · 3.79 KB
/
vite.config.js
File metadata and controls
143 lines (138 loc) · 3.79 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/// <reference types="vitest/config" />
import { defineConfig } from 'vite';
import { svelte } from '@sveltejs/vite-plugin-svelte';
import { sveltePreprocess } from 'svelte-preprocess';
import path from 'node:path';
import fs from 'node:fs';
//storybook additions
import { storybookTest } from '@storybook/addon-vitest/vitest-plugin';
// More info at: https://storybook.js.org/docs/next/writing-tests/integrations/vitest-addon
const scssOptions = {
quietDeps: true,
};
// removes the stylesheet from cloudflare.html
const removeStylesheet = () => {
return {
name: 'remove-stylesheet',
enforce: 'post',
apply: 'build',
transformIndexHtml(html) {
return html.replaceAll(/<link\s+rel="stylesheet"(\s.*\s)href="(.*)\.css">/gi, '');
},
};
};
export default defineConfig({
plugins: [
svelte({
preprocess: sveltePreprocess({
scss: {},
}),
}),
//custom vite plugin to rewrite the name of the CSS key in manifest.json
//from 'style.css' (the name of our scss file) to 'index.css' (all of our apps expect that key)
{
name: 'postbuild-commands',
writeBundle: () => {
const path = 'dist/manifest.json';
const manifest = JSON.parse(fs.readFileSync(path).toString());
if (manifest['style.css']) {
manifest['index.css'] = manifest['style.css'];
delete manifest['style.css'];
fs.writeFileSync(path, JSON.stringify(manifest, null, 2));
}
},
},
removeStylesheet(),
],
root: path.resolve(import.meta.dirname, 'src'),
publicDir: 'public',
build: {
manifest: 'manifest.json',
outDir: path.resolve(import.meta.dirname, 'dist'),
emptyOutDir: true,
cssCodeSplit: false,
rollupOptions: {
input: {
index: path.resolve(import.meta.dirname, 'src/index.html'),
cloudflare: path.resolve(import.meta.dirname, 'src/cloudflare/cloudflare.html'),
},
output: {
assetFileNames: (assetInfo) => {
if (assetInfo.names?.some((name) => name.endsWith('.css'))) {
return `assets/index-[hash][extname]`;
}
return `assets/[name]-[hash][extname]`;
},
},
external: [/^..\/fonts/, /^\/common\/firebird/],
},
},
resolve: {
extensions: ['.mjs', '.js', '.ts', '.json', '.svelte', '.scss'],
},
server: {
hot: true,
proxy: {
'^/cgi/ping': {
target: 'https://babel.hathitrust.org',
changeOrigin: true,
},
'^/cgi/ls': {
target: 'https://dev-3.babel.hathitrust.org',
changeOrigin: true,
},
},
},
css: {
preprocessorOptions: {
scss: scssOptions,
},
},
test: {
coverage: {
reporter: 'lcov',
},
projects: [
{
plugins: [
svelte({
hot: false,
compilerOptions: {
hydratable: true,
},
}),
],
test: {
name: 'default',
include: ['**/*.test.js'],
exclude: ['**/*.stories.js'],
},
},
{
extends: true,
plugins: [
// The plugin will run tests for the stories defined in your Storybook config
// See options at: https://storybook.js.org/docs/next/writing-tests/integrations/vitest-addon#storybooktest
storybookTest({
configDir: path.join(import.meta.dirname, '.storybook'),
}),
],
test: {
name: 'storybook',
root: path.resolve(import.meta.dirname),
browser: {
enabled: true,
headless: true,
provider: 'playwright',
instances: [
{
browser: 'chromium',
},
],
},
setupFiles: ['./.storybook/vitest.setup.js'],
},
},
],
},
});