-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathastro.config.mjs
147 lines (138 loc) · 3.92 KB
/
astro.config.mjs
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
144
145
146
147
import analogjsangular from '@analogjs/astro-angular';
import starlight from '@astrojs/starlight';
import tailwind from '@astrojs/tailwind';
import { defineConfig } from 'astro/config';
import glob from 'fast-glob';
import { readFileSync } from 'node:fs';
import { dirname } from 'node:path';
import starlightBlog from 'starlight-blog';
import { ngtSidebar } from './astro.sidebar.mjs';
function devServerFileWatcher(paths) {
return {
name: 'dev-server-file-watcher',
hooks: {
async 'astro:config:setup'({ addWatchFile, config }) {
for (const path of paths) {
const files = await glob(path);
files.forEach((file) => addWatchFile(new URL(file, config.root)));
}
},
},
};
}
function includeContentPlugin() {
const map = new Map();
return [
{
name: 'pre-include-content',
enforce: 'pre',
transform(_, id) {
if (!id.includes('?includeContent') || id.includes('astro-entry')) return;
const [filePath] = id.split('?');
const fileContent = readFileSync(filePath, 'utf-8');
if (map.has(filePath)) return;
map.set(filePath, fileContent.replace(/\t/g, ' '));
// check if file imports `./scene-graph`
const sceneGraphImportMatch = fileContent.match(/import.*from\s+['"]\.\/scene-graph['"]/);
if (sceneGraphImportMatch) {
// Get the directory of the current file
const dirPath = dirname(filePath);
const sceneGraphPath = `${dirPath}/scene-graph.ts`;
try {
const sceneGraphContent = readFileSync(sceneGraphPath, 'utf-8');
map.set(`${filePath}:scene-graph`, sceneGraphContent.replace(/\t/g, ' '));
} catch (error) {
// Scene graph file doesn't exist or can't be read, just continue
console.warn(`Could not read scene-graph file for ${filePath}:
${error.message}`);
}
}
},
},
{
name: 'post-include-content',
enforce: 'post',
async transform(code, id) {
if (!id.includes('?includeContent') || id.includes('astro-entry')) return;
const [filePath] = id.split('?');
const fileContent = map.get(filePath);
const sceneGraphContent = map.get(`${filePath}:scene-graph`);
return {
code: `
${code}
export const content = ${JSON.stringify(fileContent)};
export const sceneGraphContent = ${sceneGraphContent ? JSON.stringify(sceneGraphContent) : 'undefined'};
`,
};
},
},
];
}
// https://astro.build/config
export default defineConfig({
vite: {
esbuild: {
jsxDev: true,
},
plugins: [includeContentPlugin()],
ssr: {
noExternal: [
'angular-three-soba/**',
'angular-three-cannon',
'angular-three-cannon/**',
'angular-three-rapier',
'angular-three-rapier/**',
'angular-three-postprocessing',
'angular-three-postprocessing/**',
'angular-three-tweakpane',
'@pmndrs/vanilla',
'@pmndrs/cannon-worker-api',
'three-custom-shader-material',
'postprocessing',
'stats-gl',
],
},
assetsInclude: ['**/*.gltf', '**/*.glb', '**/*.png', '**/*.CUBE'],
},
integrations: [
devServerFileWatcher(['./astro.sidebar.mjs']),
analogjsangular({
vite: {
transformFilter: (_, id) => {
// we only transform files in components/scenes
return id.includes('components/scenes') || id.includes('components/soba');
},
},
}),
starlight({
title: 'Angular Three',
routeMiddleware: ['./src/route-data.ts'],
plugins: [
ngtSidebar(),
starlightBlog({
authors: {
chau: {
name: 'Chau Tran',
url: 'https://nartc.me',
picture: 'https://avatars.githubusercontent.com/u/25516557?v=4',
},
},
}),
],
favicon: '/angular-three-dark.svg',
tableOfContents: {
minHeadingLevel: 2,
maxHeadingLevel: 4,
},
logo: {
light: './src/assets/angular-three.svg',
dark: './src/assets/angular-three-dark.svg',
},
social: {
github: 'https://github.com/angular-threejs/angular-three',
},
customCss: ['./src/tailwind.css'],
}),
tailwind({ applyBaseStyles: false }),
],
});