fix(webpack): es module source mapping improvements · NativeScript/NativeScript@bbeca52 · GitHub
Skip to content

Commit bbeca52

Browse files
committed
fix(webpack): es module source mapping improvements
1 parent 2325e33 commit bbeca52

3 files changed

Lines changed: 226 additions & 45 deletions

File tree

packages/core/inspector_modules.ts

Lines changed: 103 additions & 19 deletions

packages/webpack5/src/configuration/base.ts

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { applyDotEnvPlugin } from '../helpers/dotEnv';
2424
import { env as _env, IWebpackEnv } from '../index';
2525
import { getValue } from '../helpers/config';
2626
import { getIPS } from '../helpers/host';
27+
import FixSourceMapUrlPlugin from '../plugins/FixSourceMapUrlPlugin';
2728
import {
2829
getAvailablePlatforms,
2930
getAbsoluteDistPath,
@@ -178,32 +179,9 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
178179

179180
// For ESM builds, fix the sourceMappingURL to use correct paths
180181
if (!env.commonjs && sourceMapType && sourceMapType !== 'hidden-source-map') {
181-
class FixSourceMapUrlPlugin {
182-
apply(compiler) {
183-
compiler.hooks.emit.tap('FixSourceMapUrlPlugin', (compilation) => {
184-
const leadingCharacter = process.platform === 'win32' ? '/' : '';
185-
Object.keys(compilation.assets).forEach((filename) => {
186-
if (filename.endsWith('.mjs') || filename.endsWith('.js')) {
187-
const asset = compilation.assets[filename];
188-
let source = asset.source();
189-
190-
// Replace sourceMappingURL to use file:// protocol pointing to actual location
191-
source = source.replace(
192-
/\/\/# sourceMappingURL=(.+\.map)/g,
193-
`//# sourceMappingURL=file://${leadingCharacter}${outputPath}/$1`,
194-
);
195-
196-
compilation.assets[filename] = {
197-
source: () => source,
198-
size: () => source.length,
199-
};
200-
}
201-
});
202-
});
203-
}
204-
}
205-
206-
config.plugin('FixSourceMapUrlPlugin').use(FixSourceMapUrlPlugin);
182+
config
183+
.plugin('FixSourceMapUrlPlugin')
184+
.use(FixSourceMapUrlPlugin as any, [{ outputPath }]);
207185
}
208186

209187
// when using hidden-source-map, output source maps to the `platforms/{platformName}-sourceMaps` folder
Lines changed: 119 additions & 0 deletions

0 commit comments

Comments
 (0)