-
-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generated sourcemap maybe broken #329
Comments
Same here, checked with "Source Map Visualization" and found that generated sourcemap is incorrect.
|
As for me, I worked around this issue by creating my own plugin and using it instead. I'm happy to help the author @egoist and others who are facing this issue, so I'll post the workaround here. rollup-plugin-esbuild.mjsimport { existsSync } from 'fs';
import { dirname, relative, resolve } from 'path';
import { transform } from 'esbuild';
const defaultOptions = {
treeShaking: true,
};
export default function esbuild(options) {
options = { ...defaultOptions, ...options };
options.format = 'esm';
options.loader = 'ts';
options.sourcemap = true;
return {
name: 'esbuild',
resolveId(source, importer, opts) {
// console.log('resolveId:');
// console.dir({ source, importer, opts }, { depth: null });
if (!importer || source.endsWith('.ts')) {
return source;
}
const dirPath = dirname(importer);
let path;
if (existsSync(path = resolve(dirPath, source, 'index.ts'))) {
return path;
} else if (existsSync(path = resolve(dirPath, source + '.ts'))) {
return path;
} else {
console.error({ source, importer, options: opts });
path = relative('.', resolve(importer, source));
throw new Error(`ENOENT: ${path.replace(/\\/g, '/')}`);
}
},
async transform(src, id) {
options.sourcefile = id;
const { code, map } = await transform(src, options);
return { code, map };
},
};
}; rollup.config.js// import esbuild from 'rollup-plugin-esbuild';
import esbuild from './rollup-plugin-esbuild.mjs';
export default [
// Same configuration as before
]; The above workaround only supports the |
🎉 This issue has been resolved in version 4.10.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
I think the generated sourcemap is probably broken.
Environment
Procedure for reproducing
Prepare a simple TypeScript file as shown below.
index.ts
Transpile it with the rollup config file like the following.
rollup.config.js
The following
index.js.map
is generated withindex.js
, but it seems to be broken.You can check if the SourceMap is correct by using a tool like "Source Map Visualization".
Note that the sourcemap is correct when building with
esbuild
alone, withoutrollup
and its plugins.I apologize if this is my misunderstanding or incorrect usage.
Best regards,
The text was updated successfully, but these errors were encountered: