forked from tailwindlabs/prettier-plugin-tailwindcss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtsdown.config.ts
More file actions
79 lines (71 loc) · 1.98 KB
/
tsdown.config.ts
File metadata and controls
79 lines (71 loc) · 1.98 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
import { readFile } from 'node:fs/promises'
import * as path from 'node:path'
import { defineConfig, Rolldown } from 'tsdown'
/**
* Patches jiti to use require for babel import.
*/
function patchJiti(): Rolldown.Plugin {
return {
name: 'patch-jiti',
async load(id) {
if (!/jiti[\\/]lib[\\/]jiti\.mjs$/.test(id)) {
return null
}
let original = await readFile(id, 'utf8')
return {
code: original.replace(
'createRequire(import.meta.url)("../dist/babel.cjs")',
'require("../dist/babel.cjs")',
),
}
},
}
}
/**
* Inlines CSS imports as JavaScript strings.
*/
function inlineCssImports(): Rolldown.Plugin {
return {
name: 'inline-css-imports',
async load(id) {
// Inline CSS imports
if (id.endsWith('.css')) {
let content = await readFile(id, 'utf-8')
return {
code: `export default ${JSON.stringify(content)}`,
moduleType: 'js',
}
}
// Inline preflight in v3
if (id.endsWith('corePlugins.js')) {
let preflightPath = path.resolve(path.dirname(id), './css/preflight.css')
let preflightContent = await readFile(preflightPath, 'utf-8')
let content = await readFile(id, 'utf-8')
// This is a bit fragile but this is to inline preflight for the
// *bundled* version which means a failing test should be enough
content = content.replace(
`_fs.default.readFileSync(_path.join(__dirname, "./css/preflight.css"), "utf8")`,
JSON.stringify(preflightContent),
)
return {
code: content,
}
}
return null
},
}
}
export default defineConfig({
entry: ['./src/index.ts', './src/sorter.ts'],
format: 'esm',
platform: 'node',
target: 'node14.21.3',
external: ['prettier'],
dts: true,
sourcemap: false,
fixedExtension: true,
minify: 'dce-only',
inlineOnly: false,
shims: true,
plugins: [patchJiti(), inlineCssImports()],
})