-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
107 lines (105 loc) · 2.83 KB
/
Copy pathvite.config.ts
File metadata and controls
107 lines (105 loc) · 2.83 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
import {defineConfig} from 'vite';
import type {Plugin} from 'vite';
import {hydrogen} from '@shopify/hydrogen/vite';
import {oxygen} from '@shopify/mini-oxygen/vite';
import {reactRouter} from '@react-router/dev/vite';
import tsconfigPaths from 'vite-tsconfig-paths';
/**
* Plugin to redirect vfile's Node.js imports to browser-compatible versions.
* This fixes "No such module node:path" errors on Oxygen deployment.
*/
function vfileBrowserPlugin(): Plugin {
return {
name: 'vfile-browser',
enforce: 'pre',
resolveId(id, importer) {
// Redirect vfile's internal imports to browser versions
if (importer?.includes('node_modules/vfile/')) {
// Get the vfile package root directory
const vfileRoot = importer.substring(
0,
importer.indexOf('node_modules/vfile/') +
'node_modules/vfile/'.length,
);
if (id === '#minpath') {
return {id: vfileRoot + 'lib/minpath.browser.js'};
}
if (id === '#minproc') {
return {id: vfileRoot + 'lib/minproc.browser.js'};
}
if (id === '#minurl') {
return {id: vfileRoot + 'lib/minurl.browser.js'};
}
}
return null;
},
};
}
export default defineConfig({
plugins: [
hydrogen(),
oxygen(),
reactRouter(),
tsconfigPaths(),
vfileBrowserPlugin(),
],
ssr: {
optimizeDeps: {
include: [
'@headlessui/react',
'@pack/types',
'cookie',
'crypto-js/aes',
'crypto-js/core',
'crypto-js/hmac-sha256',
'crypto-js/sha256',
'debug',
'fast-deep-equal',
'fast-xml-parser',
'hex-to-rgba',
'lodash/debounce',
'lodash/kebabCase',
'lodash/snakeCase',
'lodash/startCase',
'react-fast-marquee',
'react-markdown',
'react-router',
'remark-breaks',
'remark-gfm',
'sanitize-html',
'set-cookie-parser',
'snakecase-keys',
'use-sync-external-store/shim',
],
},
resolve: {
conditions: ['workerd', 'worker', 'browser'],
externalConditions: ['workerd', 'worker'],
},
},
optimizeDeps: {
include: [
'@headlessui/react',
'@pack/react',
'@shopify/hydrogen-react',
'react-intersection-observer',
'swiper/modules',
'swiper/react',
],
},
server: {
headers: {
// Allow Private Network Access from public origins (e.g., hosted iframe)
'Access-Control-Allow-Private-Network': 'true',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Headers': '*',
},
allowedHosts: [],
},
build: {
// Allow a strict Content-Security-Policy
// withtout inlining assets as base64:
assetsInlineLimit: 0,
},
});