Skip to content

Commit

Permalink
fix sourcemap
Browse files Browse the repository at this point in the history
  • Loading branch information
indooorsman committed Sep 28, 2023
1 parent 59c143c commit c39b4c8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 21 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## V3.0.3
- Fix sourcemap

## V3.0.2
- Do not emit .d.ts for files outside of build root

Expand Down
19 changes: 6 additions & 13 deletions lib/css.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import { dirname, relative, resolve } from 'node:path';
import {
contentPlaceholder,
digestPlaceholder,
emptySourceMap,
pluginCssNamespace,
validateNamedExport
} from './utils.js';
import { camelCase, sortBy, uniq, uniqBy, upperFirst } from 'lodash-es';
import { camelCase, sortBy, uniqBy, upperFirst } from 'lodash-es';
import { injectorVirtualPath, pluginJsNamespace } from './utils.js';
import { readFileSync } from 'node:fs';

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

// https://github.com/evanw/esbuild/issues/1227
jsLines.push(`//${emptySourceMap}`);

const jsContents = jsLines.join('\n');

return { js: jsContents, dts: emitDts ? dtsLines.join('\n') : undefined };
Expand Down Expand Up @@ -268,12 +264,14 @@ ${uniqNames.map(([o, l]) => ` "${o}": ${l}`).join(',\n')}
},
errorRecovery: true,
minify: false,
sourceMap: !!this.build.initialOptions.sourcemap,
sourceMap: false,
projectRoot: this.build.context.buildRoot,
targets: {
chrome: 112 << 16
}
};
/** @type {{code: Buffer, exports: import('lightningcss').CSSModuleExports}} */
// @ts-ignore
const r = bundleModulesCss(bundleCssConfig);

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

const { code, map: sourcemap, exports } = r;
const { code, exports } = r;

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

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

const css =
originCss +
(sourcemap
? `\n/*# sourceMappingURL=data:application/json;base64,${sourcemap.toString('base64')} */`
: '');
const { js, dts } = this.genModulesJs(exports, fullpath, !!opt?.emitDeclarationFile);
/** @type {{css: string; js: string; dts?: string; composedFiles: string[]}} */
const result = {
css,
css: originCss,
composedFiles,
js,
dts
Expand Down
4 changes: 0 additions & 4 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,6 @@ const validateNamedExport = (name) => {
return !jsKeywords.includes(name);
};

const emptySourceMap =
'# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==';

const contentPlaceholder = '__content_placeholder__';
const digestPlaceholder = '__digest_placeholder__';

Expand Down Expand Up @@ -234,7 +231,6 @@ export {
getBuildId,
validateNamedExport,
getPackageInfo,
emptySourceMap,
contentPlaceholder,
digestPlaceholder,
relativeToCwd,
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "esbuild-css-modules-plugin",
"version": "3.0.2",
"version": "3.0.3",
"description": "A esbuild plugin to bundle css modules into js(x)/ts(x), based on extremely fast [Lightning CSS](https://lightningcss.dev/)",
"main": "./index.cjs",
"module": "./index.js",
Expand Down Expand Up @@ -38,14 +38,13 @@
"devDependencies": {
"@types/lodash-es": "^4.17.7",
"@types/node": "^17.0.23",
"esbuild": "^0.19.2"
"esbuild": "^0.19.4"
},
"peerDependencies": {
"esbuild": "*"
},
"dependencies": {
"lightningcss": "^1.21.7",
"lodash": "^4.17.21",
"lightningcss": "^1.22.0",
"lodash-es": "^4.17.21"
},
"publishConfig": {
Expand Down

0 comments on commit c39b4c8

Please sign in to comment.