-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
/
Copy pathvite.config.js
117 lines (111 loc) · 2.7 KB
/
vite.config.js
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
const fs = require('fs')
const vue = require('@vitejs/plugin-vue')
// Overriding the NODE_ENV set by vitest
process.env.NODE_ENV = ''
/**
* @type {import('vite').UserConfig}
*/
module.exports = {
resolve: {
dedupe: ['react'],
alias: {
'node:url': 'url'
}
},
optimizeDeps: {
include: ['dep-linked-include', 'nested-exclude > nested-include'],
exclude: ['nested-exclude'],
esbuildOptions: {
plugins: [
{
name: 'replace-a-file',
setup(build) {
build.onLoad(
{ filter: /dep-esbuild-plugin-transform(\\|\/)index\.js$/ },
() => ({
contents: `export const hello = () => 'Hello from an esbuild plugin'`,
loader: 'js'
})
)
}
}
]
},
entries: ['entry.js']
},
build: {
// to make tests faster
minify: false
},
plugins: [
vue(),
notjs(),
// for axios request test
{
name: 'mock',
configureServer({ middlewares }) {
middlewares.use('/ping', (_, res) => {
res.statusCode = 200
res.end('pong')
})
}
},
{
name: 'test-astro',
transform(code, id) {
if (id.endsWith('.astro')) {
code = `export default {}`
return { code }
}
}
},
// TODO: Remove this one support for prebundling in build lands.
// It is expected that named importing in build doesn't work
// as it incurs a lot of overhead in build.
{
name: 'polyfill-named-fs-build',
apply: 'build',
enforce: 'pre',
load(id) {
if (id === '__vite-browser-external:fs') {
return `export default {}; export function readFileSync() {}`
}
}
}
]
}
// Handles .notjs file, basically remove wrapping <notjs> and </notjs> tags
function notjs() {
return {
name: 'notjs',
config() {
return {
optimizeDeps: {
extensions: ['.notjs'],
esbuildOptions: {
plugins: [
{
name: 'esbuild-notjs',
setup(build) {
build.onLoad({ filter: /\.notjs$/ }, ({ path }) => {
let contents = fs.readFileSync(path, 'utf-8')
contents = contents
.replace('<notjs>', '')
.replace('</notjs>', '')
return { contents, loader: 'js' }
})
}
}
]
}
}
}
},
transform(code, id) {
if (id.endsWith('.notjs')) {
code = code.replace('<notjs>', '').replace('</notjs>', '')
return { code }
}
}
}
}