-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
/
vite.config.js
87 lines (83 loc) · 2.54 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
import path from 'node:path'
import stylus from 'stylus'
import { defineConfig } from 'vite'
// trigger scss bug: https://github.com/sass/dart-sass/issues/710
// make sure Vite handles safely
// @ts-expect-error refer to https://github.com/vitejs/vite/pull/11079
globalThis.window = {}
// @ts-expect-error refer to https://github.com/vitejs/vite/pull/11079
globalThis.location = new URL('http://localhost/')
export default defineConfig({
build: {
cssTarget: 'chrome61',
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes('manual-chunk.css')) {
return 'dir/dir2/manual-chunk'
}
},
},
},
},
esbuild: {
logOverride: {
'unsupported-css-property': 'silent',
},
},
resolve: {
alias: {
'=': __dirname,
spacefolder: __dirname + '/folder with space',
'#alias': __dirname + '/aliased/foo.css',
'#alias?inline': __dirname + '/aliased/foo.css?inline',
'#alias-module': __dirname + '/aliased/bar.module.css',
},
},
css: {
modules: {
generateScopedName: '[name]__[local]___[hash:base64:5]',
// example of how getJSON can be used to generate
// typescript typings for css modules class names
// getJSON(cssFileName, json, _outputFileName) {
// let typings = 'declare const classNames: {\n'
// for (let className in json) {
// typings += ` "${className}": string;\n`
// }
// typings += '};\n'
// typings += 'export default classNames;\n'
// const { join, dirname, basename } = require('path')
// const typingsFile = join(
// dirname(cssFileName),
// basename(cssFileName) + '.d.ts'
// )
// require('fs').writeFileSync(typingsFile, typings)
// },
},
preprocessorOptions: {
scss: {
additionalData: `$injectedColor: orange;`,
importer: [
function (url) {
return url === 'virtual-dep' ? { contents: '' } : null
},
function (url) {
return url.endsWith('.wxss') ? { contents: '' } : null
},
],
},
styl: {
additionalData: `$injectedColor ?= orange`,
imports: [
'./options/relative-import.styl',
path.join(__dirname, 'options/absolute-import.styl'),
],
define: {
$definedColor: new stylus.nodes.RGBA(51, 197, 255, 1),
definedFunction: () => new stylus.nodes.RGBA(255, 0, 98, 1),
},
},
},
preprocessorMaxWorkers: true,
},
})