summaryrefslogtreecommitdiff
path: root/packages/renderers/renderer-solid/index.js
blob: a764e5f6462900425a7a7feb7f2bcac81edea9bd (plain) (blame)
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
export default {
	name: '@astrojs/renderer-solid',
	client: './client.js',
	server: './server.js',
	jsxImportSource: 'solid-js',
	jsxTransformOptions: async ({ ssr }) => {
		const [{ default: solid }] = await Promise.all([import('babel-preset-solid')]);
		const options = {
			presets: [solid({}, { generate: ssr ? 'ssr' : 'dom', hydratable: true })],
			plugins: [],
		};

		if (ssr) {
			options.plugins.push([
				'babel-plugin-module-resolver',
				{
					cwd: process.cwd(),
					alias: {
						'solid-js/store': 'solid-js/store/dist/server.js',
						'solid-js/web': 'solid-js/web/dist/server.js',
						'solid-js': 'solid-js/dist/server.js',
					},
				},
			]);
		}

		return options;
	},
	viteConfig(options) {
		// https://github.com/solidjs/vite-plugin-solid

		// We inject the dev mode only if the user explicitely wants it or if we are in dev (serve) mode
		const replaceDev = options.mode === 'development' || options.command === 'serve';

		const nestedDeps = ['solid-js', 'solid-js/web', 'solid-js/store', 'solid-js/html', 'solid-js/h'];

		return {
			/**
			 * We only need esbuild on .ts or .js files.
			 * .tsx & .jsx files are handled by us
			 */
			esbuild: { include: /\.ts$/ },
			resolve: {
				conditions: ['solid', ...(replaceDev ? ['development'] : [])],
				dedupe: nestedDeps,
				alias: [{ find: /^solid-refresh$/, replacement: '/@solid-refresh' }],
			},
			optimizeDeps: {
				include: nestedDeps,
				exclude: ['@astrojs/renderer-solid/server.js'],
			},
			ssr: {
				external: ['solid-js/web/dist/server.js', 'solid-js/store/dist/server.js', 'solid-js/dist/server.js', 'babel-preset-solid'],
			},
		};
	},
};