-
-
Notifications
You must be signed in to change notification settings - Fork 163
Expand file tree
/
Copy pathtsdown.config.ts
More file actions
104 lines (96 loc) · 2.66 KB
/
Copy pathtsdown.config.ts
File metadata and controls
104 lines (96 loc) · 2.66 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
94
95
96
97
98
99
100
101
102
103
104
import autoprefixer from 'autoprefixer'
import cssnano from 'cssnano'
import postcssUrl from 'postcss-url'
import { NodePackageImporter } from 'sass-embedded'
import { defineConfig } from 'tsdown'
import type { UserConfig } from 'tsdown'
import packageJson from './package.json' with { type: 'json' }
import { postcssOptimizeDefaultTheme } from './scripts/postcss-optimize-default-theme.ts'
import { createRolldownChunkStringContext } from './scripts/rolldown-chunk-string-context-plugin.ts'
const { peerDependencies } = packageJson
const browserScriptContext = createRolldownChunkStringContext({
name: 'marp-core-browser-script',
})
const baseConfig = {
minify: true,
outDir: 'lib',
outputOptions: { exports: 'named' },
sourcemap: true,
css: {
target: false,
transformer: 'postcss',
postcss: {
plugins: [
postcssOptimizeDefaultTheme(),
(postcssUrl as any)({
filter: '**/assets/**/*.svg',
encodeType: 'base64',
url: 'inline',
}),
autoprefixer(),
cssnano({
// Whitespace normalizer will apply on runtime to make debug easily (minifyCSS option)
preset: ['default', { normalizeWhitespace: false }],
}),
],
},
preprocessorOptions: { scss: { importers: [new NodePackageImporter()] } },
},
deps: {
neverBundle: /^#marp-/,
dts: { alwaysBundle: ['markdown-it'] },
},
dts: { resolver: 'tsc' },
} as const satisfies UserConfig
const browserBaseConfig: UserConfig = {
...baseConfig,
platform: 'browser',
deps: { alwaysBundle: () => true },
}
const internalConfig: UserConfig = { ...baseConfig, dts: false }
export default defineConfig([
// Browser helpers
{
...browserBaseConfig,
entry: 'src/browser-iife.ts',
name: 'Browser script (iife)',
outputOptions: { exports: 'none' },
format: 'iife',
plugins: [browserScriptContext.sourcePlugin()],
},
{
...browserBaseConfig,
entry: 'src/browser.ts',
name: 'Browser module',
format: ['esm', 'cjs'],
},
// Internals
{
...internalConfig,
entry: { 'internals/*': 'src/internals/*.ts' },
format: ['esm', 'cjs'],
},
// Main bundle
browserScriptContext.withTarget(
{
...baseConfig,
entry: {
index: 'src/index.ts',
full: 'src/full.ts',
'plugins/*': 'src/plugins/*/index.ts',
},
format: ['esm', 'cjs'],
deps: {
...baseConfig.deps,
dts: {
...baseConfig.deps.dts,
alwaysBundle: [
...baseConfig.deps.dts.alwaysBundle,
...Object.keys(peerDependencies),
],
},
},
},
{ importSource: './browser-script' },
),
])