Repository navigation
Expand file tree
/
Copy pathvite.config.js
More file actions
93 lines (86 loc) · 2.59 KB
/
Copy pathvite.config.js
File metadata and controls
93 lines (86 loc) · 2.59 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
import tailwindcss from '@tailwindcss/vite';
import react from '@vitejs/plugin-react';
import postcss from 'postcss';
import { defineConfig } from 'vite';
import dts from 'vite-plugin-dts';
import svgr from 'vite-plugin-svgr';
import { resolve } from 'path';
import { fileURLToPath } from 'url';
const __dirname = fileURLToPath(new URL('.', import.meta.url));
/**
* Vite plugin that strips CSS @layer wrappers from the built stylesheet.
*
* Tailwind CSS v4 wraps all utilities in @layer directives. In the CSS cascade,
* layered styles always lose to unlayered styles — so when a non-Tailwind consumer
* imports dist/style.css alongside their own regular CSS, the picker's styles get
* overridden. This plugin unwraps the @layer blocks (keeping the rules inside) so
* the distributed CSS works reliably as a standalone stylesheet.
*
* Only runs during `vite build` — the dev server is unaffected.
*/
function stripCssLayers() {
return {
name: 'strip-css-layers',
apply: 'build',
async writeBundle(options) {
const fs = await import('fs');
const path = await import('path');
const outDir = options.dir || resolve(__dirname, 'dist');
const cssPath = path.resolve(outDir, 'style.css');
if (!fs.existsSync(cssPath)) return;
const css = fs.readFileSync(cssPath, 'utf-8');
const root = postcss.parse(css);
root.walkAtRules('layer', (rule) => {
if (rule.nodes && rule.nodes.length > 0) {
rule.replaceWith(rule.nodes);
} else {
rule.remove();
}
});
fs.writeFileSync(cssPath, root.toString());
},
};
}
// https://vitejs.dev/config/
export default defineConfig({
test: {
environment: 'jsdom',
globals: true,
},
plugins: [
tailwindcss(),
react(),
svgr(),
dts({
rollupTypes: true,
tsconfigPath: resolve(__dirname, 'tsconfig-build.json'),
}),
stripCssLayers(),
],
server: {
port: 3000,
},
build: {
copyPublicDir: false,
lib: {
entry: resolve(__dirname, './src/lib/index.tsx'),
formats: ['es', 'umd', 'cjs'],
name: 'react-tailwindcss-datetimepicker',
cssFileName: 'style',
},
rollupOptions: {
// make sure to externalize deps that shouldn't be bundled
// into your library
external: ['react', 'react-dom', 'react/jsx-runtime'],
output: {
// Provide global variables to use in the UMD build
// for externalized deps
globals: {
react: 'React',
'react-dom': 'ReactDOM',
'react/jsx-runtime': 'react/jsx-runtime',
},
},
},
},
});