-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
90 lines (86 loc) · 2.55 KB
/
vite.config.ts
File metadata and controls
90 lines (86 loc) · 2.55 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
import { defineConfig } from 'vite'
import inject from '@rollup/plugin-inject'
import stdLibBrowser from 'node-stdlib-browser'
import { createRequire } from 'module'
import { readFile } from 'fs/promises'
const require = createRequire(import.meta.url);
const empty = require.resolve('./src/stubs/empty.ts');
const browserShimsPath = require.resolve('node-stdlib-browser/helpers/esbuild/shim');
let preflightCss = await readFile(require.resolve('tailwindcss/lib/css/preflight.css'), 'utf8');
preflightCss = '`' + preflightCss.replaceAll('`', '\\`') + '`'
function embedPreflight(source: string) {
return source.replace(
'_fs.default.readFileSync(_path.join(__dirname, "./css/preflight.css"), "utf8")',
preflightCss
);
}
export default defineConfig(({ command }) => ({
build: {
lib: {
entry: './src/index.ts',
name: 'TailwindCssLib',
fileName: 'tailwindcss-lib'
}
},
define: {
'process.env.OXIDE': 'false',
'env.OXIDE': 'false'
},
resolve: {
alias: {
...stdLibBrowser,
'lightningcss': empty,
'browserslist': empty,
'@tailwindcss/oxide': empty,
'source-map-js': 'node_modules/source-map-js/source-map.js',
'fast-glob': require.resolve('./src/stubs/fast-glob.ts'),
},
},
plugins: [
{
name: 'wrapped-inject',
enforce: 'post',
async transform(code, id) {
const original = inject({
global: [browserShimsPath, 'global'],
process: [browserShimsPath, 'process'],
Buffer: [browserShimsPath, 'Buffer'],
sourceMap: command === 'serve'
});
if (typeof original.transform !== 'function') {
throw new TypeError("Expected inject's transform handler to be a function");
}
const result = await original.transform.call(this, code, id);
if (result && typeof result !== 'string') {
delete result.map;
}
return result;
}
},
{
name: 'preflight-fix',
transform(code, id) {
if (id.includes('tailwindcss') && id.includes('corePlugins')) {
return embedPreflight(code);
}
return null;
}
}
],
optimizeDeps: {
include: ['buffer', 'process'],
esbuildOptions: {
plugins: [
{
name: 'preflight-fix',
setup(build) {
build.onLoad({ filter: /tailwindcss.*corePlugins/ }, async (args) => {
const source = await readFile(args.path, 'utf8');
return { contents: embedPreflight(source) };
})
}
}
]
}
}
}));