diff --git a/changelog.md b/changelog.md index edb6705..d030717 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,6 @@ +## V3.0.3 +- Fix sourcemap + ## V3.0.2 - Do not emit .d.ts for files outside of build root diff --git a/lib/css.helper.js b/lib/css.helper.js index 927485d..edc407a 100644 --- a/lib/css.helper.js +++ b/lib/css.helper.js @@ -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'; @@ -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 }; @@ -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) }); @@ -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') : ''; @@ -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 diff --git a/lib/utils.js b/lib/utils.js index 2ccc568..47f52bd 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -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__'; @@ -234,7 +231,6 @@ export { getBuildId, validateNamedExport, getPackageInfo, - emptySourceMap, contentPlaceholder, digestPlaceholder, relativeToCwd, diff --git a/package.json b/package.json index ec40ad8..ea75e6f 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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": {