forked from Shopify/hydrogen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
64 lines (62 loc) · 2.05 KB
/
Copy pathvite.config.ts
File metadata and controls
64 lines (62 loc) · 2.05 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
import {croct} from '@croct/plug-hydrogen/vite';
import {fileURLToPath} from 'node:url';
import {defineConfig} from 'vite';
import {hydrogen} from '@shopify/hydrogen/vite';
import {oxygen} from '@shopify/mini-oxygen/vite';
import {reactRouter} from '@react-router/dev/vite';
// Vercel deployments run on Node.js instead of Oxygen's worker runtime:
// the Oxygen plugin is dropped, the SSR bundle uses the Vercel server
// entrypoint, and React DOM streams through the Web Streams build.
const isVercel = process.env.VERCEL === '1';
export default defineConfig(({isSsrBuild}) => ({
plugins: [
hydrogen(),
...(isVercel ? [] : [oxygen()]),
reactRouter(),
croct(),
],
resolve: {
alias: {
// Vite's native tsconfig path resolver does not cover JavaScript
// projects that use jsconfig.json, so define Hydrogen's app alias here.
'~': fileURLToPath(new URL('./app', import.meta.url)),
...(isVercel && isSsrBuild
? {'react-dom/server': 'react-dom/server.browser'}
: {}),
},
tsconfigPaths: true,
},
build: {
// Allow a strict Content-Security-Policy
// without inlining assets as base64:
assetsInlineLimit: 0,
...(isVercel && isSsrBuild
? {rollupOptions: {input: './server/vercel.ts'}}
: {}),
},
ssr: {
// The Croct SDK imports the virtual config module generated by the
// croct() plugin, so it must be bundled rather than externalized
...(isVercel ? {noExternal: [/^@croct\//]} : {}),
optimizeDeps: {
/**
* Include dependencies here if they throw CJS<>ESM errors.
* For example, for the following error:
*
* > ReferenceError: module is not defined
* > at /Users/.../node_modules/example-dep/index.js:1:1
*
* Include 'example-dep' in the array below.
* @see https://vitejs.dev/config/dep-optimization-options
*/
include: [
'react-router > set-cookie-parser',
'react-router > cookie',
'react-router',
],
},
},
server: {
allowedHosts: ['.tryhydrogen.dev'],
},
}));