|
8 | 8 |
|
9 | 9 | import type { Location, OnLoadResult, PluginBuild } from 'esbuild';
|
10 | 10 | import { readFile } from 'node:fs/promises';
|
11 |
| -import { isAbsolute } from 'node:path'; |
12 |
| -import { pathToFileURL } from 'node:url'; |
13 | 11 | import { StylesheetLanguage, StylesheetPluginOptions } from './stylesheet-plugin-factory';
|
14 | 12 |
|
15 | 13 | /**
|
@@ -115,24 +113,22 @@ async function compileString(
|
115 | 113 | };
|
116 | 114 |
|
117 | 115 | try {
|
118 |
| - const { imports, map, css } = await less.render(data, { |
| 116 | + const { imports, css } = await less.render(data, { |
119 | 117 | filename,
|
120 | 118 | paths: options.includePaths,
|
121 | 119 | plugins: [resolverPlugin],
|
122 | 120 | rewriteUrls: 'all',
|
123 | 121 | javascriptEnabled: unsafeInlineJavaScript,
|
124 | 122 | sourceMap: options.sourcemap
|
125 | 123 | ? {
|
126 |
| - sourceMapFileInline: false, |
| 124 | + sourceMapFileInline: true, |
127 | 125 | outputSourceFiles: true,
|
128 | 126 | }
|
129 | 127 | : undefined,
|
130 | 128 | } as Less.Options);
|
131 | 129 |
|
132 | 130 | return {
|
133 |
| - // There can be cases where `less` will return an undefined `map` even |
134 |
| - // though the types do not specify this as a possibility. |
135 |
| - contents: map ? `${css}\n${sourceMapToUrlComment(map)}` : css, |
| 131 | + contents: css, |
136 | 132 | loader: 'css',
|
137 | 133 | watchFiles: [filename, ...imports],
|
138 | 134 | };
|
@@ -194,18 +190,3 @@ function convertExceptionLocation(exception: LessException): Partial<Location> {
|
194 | 190 | lineText: exception.extract && exception.extract[Math.trunc(exception.extract.length / 2)],
|
195 | 191 | };
|
196 | 192 | }
|
197 |
| - |
198 |
| -function sourceMapToUrlComment(sourceMap: string): string { |
199 |
| - // eslint-disable-next-line @typescript-eslint/no-explicit-any |
200 |
| - const map = JSON.parse(sourceMap) as Record<string, any>; |
201 |
| - // Using file URLs instead of paths ensures that esbuild correctly resolves the source map. |
202 |
| - // https://github.com/evanw/esbuild/issues/4070 |
203 |
| - // https://github.com/evanw/esbuild/issues/4075 |
204 |
| - map.sources = map.sources.map((source: string) => |
205 |
| - source && isAbsolute(source) ? pathToFileURL(source).href : source, |
206 |
| - ); |
207 |
| - |
208 |
| - const urlSourceMap = Buffer.from(JSON.stringify(map), 'utf-8').toString('base64'); |
209 |
| - |
210 |
| - return `/*# sourceMappingURL=data:application/json;charset=utf-8;base64,${urlSourceMap} */`; |
211 |
| -} |
0 commit comments