Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions integrations/cli/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ describe.each([
expect(map.at(4, 0)).toMatchObject({
source: null,
original: '(none)',
generated: '}...',
generated: '}\n\n/*# sou...',
})
},
)
Expand Down Expand Up @@ -815,7 +815,7 @@ describe.each([
expect(map.at(4, 0)).toMatchObject({
source: null,
original: '(none)',
generated: '}...',
generated: '}\n\n/*# sou...',
})
},
)
Expand Down Expand Up @@ -1118,7 +1118,7 @@ describe.each([
expect(map.at(4, 0)).toMatchObject({
source: null,
original: '(none)',
generated: '}...',
generated: '}\n\n/*# sou...',
})

// Write to project source files
Expand Down Expand Up @@ -1190,7 +1190,7 @@ describe.each([
expect(map.at(7, 0)).toMatchObject({
source: null,
original: '(none)',
generated: '}...',
generated: '}\n\n/*# sou...',
})

// Write to the main CSS file
Expand Down Expand Up @@ -1290,7 +1290,7 @@ describe.each([
expect(map.at(10, 0)).toMatchObject({
source: null,
original: '(none)',
generated: '}...',
generated: '}\n\n/*# sou...',
})
},
)
Expand Down
12 changes: 12 additions & 0 deletions packages/@tailwindcss-cli/src/commands/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,18 @@ export async function handle(args: Result<ReturnType<typeof options>>) {
output += `\n`
output += map.inline
} else if (typeof args['--map'] === 'string') {
let basePath =
args['--output'] && args['--output'] !== '-'
? path.dirname(path.resolve(args['--output']))
: process.cwd()

let mapPath = path.resolve(args['--map'])

let relativePath = path.relative(basePath, mapPath)

output += `\n`
output += map.comment(relativePath)

DEBUG && I.start('Write source map')
await outputFile(args['--map'], map.raw)
DEBUG && I.end('Write source map')
Expand Down
15 changes: 8 additions & 7 deletions packages/@tailwindcss-node/src/source-maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type { DecodedSource, DecodedSourceMap }
export interface SourceMap {
readonly raw: string
readonly inline: string
comment(url: string): string
}

function serializeSourceMap(map: DecodedSourceMap): string {
Expand Down Expand Up @@ -44,16 +45,16 @@ function serializeSourceMap(map: DecodedSourceMap): string {
export function toSourceMap(map: DecodedSourceMap | string): SourceMap {
let raw = typeof map === 'string' ? map : serializeSourceMap(map)

function comment(url: string) {
return `/*# sourceMappingURL=${url} */\n`
}

return {
raw,
get inline() {
let tmp = ''

tmp += '/*# sourceMappingURL=data:application/json;base64,'
tmp += Buffer.from(raw, 'utf-8').toString('base64')
tmp += ' */\n'

return tmp
let inlined = Buffer.from(raw, 'utf-8').toString('base64')
return comment(`data:application/json;base64,${inlined}`)
},
comment,
}
}