Skip to content

Commit

Permalink
fix: Source maps in export-default-simplify plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
rschristian committed Jan 8, 2025
1 parent eb58a42 commit e35bc4d
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 25 deletions.
82 changes: 61 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"gzip-size": "^6.0.0",
"kleur": "^4.1.5",
"lodash.merge": "^4.6.2",
"magic-string": "^0.30.17",
"postcss": "^8.2.1",
"pretty-bytes": "^5.6.0",
"rollup": "^2.70.2",
Expand Down
11 changes: 7 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
import { getConfigFromPkgJson, getName } from './lib/package-info';
import { shouldCssModules, cssModulesConfig } from './lib/css-modules';
import { EOL } from 'os';
import MagicString from 'magic-string';

// Extensions to use when resolving modules
const EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.es6', '.es', '.mjs'];
Expand Down Expand Up @@ -599,15 +600,17 @@ function createConfig(options, entry, format, writeMeta) {
({
name: 'export-default-simplify',
renderChunk(code, chunk, options) {
let out = code.replace(
const s = new MagicString(code);
s.replace(
/([};\n])export\s*\{\s*([a-zA-Z0-9_$]+)\s+as\s+default\s*\};/,
(s, before, name) => {
return `${before}export default ${name};`;
},
);
if (out !== code) {
return { code: out, map: null };
}
return {
code: s.toString(),
map: s.generateMap({ hires: true }),
};
},
}),
options.compress !== false && [
Expand Down

0 comments on commit e35bc4d

Please sign in to comment.