Setting the file. One moment.
Subchapter 8.27
references/option-sourcemap.mdMarkdown5 KBView on GitHub
Source maps map minified/bundled code back to original source files, making debugging significantly easier by showing original line numbers and variable names.
tsdown --sourcemap
# Or inline
tsdown --sourcemap inlineexport default defineConfig({
entry: ['src/index.ts'],
sourcemap: true,
})Generates separate .map files:
export default defineConfig({
sourcemap: true, // or 'external'
})Output:
dist/index.mjsdist/index.mjs.mapPros:
Embeds source maps in the bundle:
export default defineConfig({
sourcemap: 'inline',
})Output:
dist/index.mjs (includes source map as data URL)Pros:
Cons:
Generates map files without reference comment:
export default defineConfig({
sourcemap: 'hidden',
})Output:
dist/index.mjs (no //# sourceMappingURL comment)dist/index.mjs.mapUse when:
If declarationMap is enabled in tsconfig.json, source maps are automatically enabled:
// tsconfig.json
{
"compilerOptions": {
"declarationMap": true
}
}This also generates .d.ts.map files for TypeScript declarations.
export default defineConfig((options) => ({
entry: ['src/index.ts'],
sourcemap: options.watch, // Only in dev
minify: !options.watch,
}))export default defineConfig({
entry: ['src/index.ts'],
format: ['esm', 'cjs'],
sourcemap: true, // External maps
minify: true,
})Deploy maps to separate error reporting service.
export default defineConfig({
entry: ['src/index.ts'],
format: ['esm'],
sourcemap: 'inline',
})export default defineConfig({
entry: ['src/index.ts'],
format: {
esm: {
sourcemap: true,
},
iife: {
sourcemap: 'inline', // Inline for browser
},
},
})export default defineConfig({
entry: ['src/index.ts'],
format: ['esm', 'cjs'],
sourcemap: true,
dts: {
sourcemap: true, // Enable declaration maps
},
})Output:
dist/index.mjs + dist/index.mjs.mapdist/index.cjs + dist/index.cjs.mapdist/index.d.ts + dist/index.d.ts.map| Type | Bundle Size | Parse Speed | Debugging |
|---|---|---|---|
| None | Smallest | Fastest | Hard |
| External | Small | Fast | Easy |
| Inline | Largest | Slower | Easy |
| Hidden | Small | Fast | Tools only |
# Enable source maps
tsdown --sourcemap
# Inline source maps
tsdown --sourcemap inline
# Hidden source maps
tsdown --sourcemap hidden
# Development with source maps
tsdown --watch --sourcemap
# Production with external maps
tsdown --minify --sourcemap
# No source maps
tsdown --no-sourcemapexport default defineConfig({
sourcemap: true,
minify: false,
})export default defineConfig({
sourcemap: 'external', // Upload to error service
minify: true,
})export default defineConfig({
format: ['iife'],
platform: 'browser',
sourcemap: 'inline', // Self-contained
globalName: 'MyLib',
})export default defineConfig({
format: ['esm'],
platform: 'node',
sourcemap: true,
shims: true,
}).map files are generated//# sourceMappingURL= commentUse external source maps instead of inline:
export default defineConfig({
sourcemap: true, // Not 'inline'
})sourceRoot in generated mapsources arraySource