Skip to content

Commit c39b4c8

Browse files
committed
fix sourcemap
1 parent 59c143c commit c39b4c8

File tree

4 files changed

+12
-21
lines changed

4 files changed

+12
-21
lines changed

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## V3.0.3
2+
- Fix sourcemap
3+
14
## V3.0.2
25
- Do not emit .d.ts for files outside of build root
36

lib/css.helper.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ import { dirname, relative, resolve } from 'node:path';
33
import {
44
contentPlaceholder,
55
digestPlaceholder,
6-
emptySourceMap,
76
pluginCssNamespace,
87
validateNamedExport
98
} from './utils.js';
10-
import { camelCase, sortBy, uniq, uniqBy, upperFirst } from 'lodash-es';
9+
import { camelCase, sortBy, uniqBy, upperFirst } from 'lodash-es';
1110
import { injectorVirtualPath, pluginJsNamespace } from './utils.js';
1211
import { readFileSync } from 'node:fs';
1312

@@ -235,9 +234,6 @@ ${uniqNames.map(([o, l]) => ` "${o}": ${l}`).join(',\n')}
235234
`);
236235
}
237236

238-
// https://github.com/evanw/esbuild/issues/1227
239-
jsLines.push(`//${emptySourceMap}`);
240-
241237
const jsContents = jsLines.join('\n');
242238

243239
return { js: jsContents, dts: emitDts ? dtsLines.join('\n') : undefined };
@@ -268,12 +264,14 @@ ${uniqNames.map(([o, l]) => ` "${o}": ${l}`).join(',\n')}
268264
},
269265
errorRecovery: true,
270266
minify: false,
271-
sourceMap: !!this.build.initialOptions.sourcemap,
267+
sourceMap: false,
272268
projectRoot: this.build.context.buildRoot,
273269
targets: {
274270
chrome: 112 << 16
275271
}
276272
};
273+
/** @type {{code: Buffer, exports: import('lightningcss').CSSModuleExports}} */
274+
// @ts-ignore
277275
const r = bundleModulesCss(bundleCssConfig);
278276

279277
const t = transform({ ...bundleCssConfig, code: readFileSync(fullpath) });
@@ -289,7 +287,7 @@ ${uniqNames.map(([o, l]) => ` "${o}": ${l}`).join(',\n')}
289287
});
290288
});
291289

292-
const { code, map: sourcemap, exports } = r;
290+
const { code, exports } = r;
293291

294292
let originCss = code ? code.toString('utf8') : '';
295293

@@ -324,15 +322,10 @@ ${uniqNames.map(([o, l]) => ` "${o}": ${l}`).join(',\n')}
324322
originCss = outputFiles.find((f) => f.path.endsWith(`stdin.css`))?.text ?? originCss;
325323
}
326324

327-
const css =
328-
originCss +
329-
(sourcemap
330-
? `\n/*# sourceMappingURL=data:application/json;base64,${sourcemap.toString('base64')} */`
331-
: '');
332325
const { js, dts } = this.genModulesJs(exports, fullpath, !!opt?.emitDeclarationFile);
333326
/** @type {{css: string; js: string; dts?: string; composedFiles: string[]}} */
334327
const result = {
335-
css,
328+
css: originCss,
336329
composedFiles,
337330
js,
338331
dts

lib/utils.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,6 @@ const validateNamedExport = (name) => {
168168
return !jsKeywords.includes(name);
169169
};
170170

171-
const emptySourceMap =
172-
'# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==';
173-
174171
const contentPlaceholder = '__content_placeholder__';
175172
const digestPlaceholder = '__digest_placeholder__';
176173

@@ -234,7 +231,6 @@ export {
234231
getBuildId,
235232
validateNamedExport,
236233
getPackageInfo,
237-
emptySourceMap,
238234
contentPlaceholder,
239235
digestPlaceholder,
240236
relativeToCwd,

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "esbuild-css-modules-plugin",
3-
"version": "3.0.2",
3+
"version": "3.0.3",
44
"description": "A esbuild plugin to bundle css modules into js(x)/ts(x), based on extremely fast [Lightning CSS](https://lightningcss.dev/)",
55
"main": "./index.cjs",
66
"module": "./index.js",
@@ -38,14 +38,13 @@
3838
"devDependencies": {
3939
"@types/lodash-es": "^4.17.7",
4040
"@types/node": "^17.0.23",
41-
"esbuild": "^0.19.2"
41+
"esbuild": "^0.19.4"
4242
},
4343
"peerDependencies": {
4444
"esbuild": "*"
4545
},
4646
"dependencies": {
47-
"lightningcss": "^1.21.7",
48-
"lodash": "^4.17.21",
47+
"lightningcss": "^1.22.0",
4948
"lodash-es": "^4.17.21"
5049
},
5150
"publishConfig": {

0 commit comments

Comments
 (0)