Skip to content

Commit 82b06ba

Browse files
committed
chore: Replace it with source-map-js and prebundle it
1 parent 075c2bb commit 82b06ba

File tree

6 files changed

+27
-16
lines changed

6 files changed

+27
-16
lines changed

packages/core/modern.config.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import path from 'node:path';
12
import { defineConfig } from '@modern-js/module-tools';
23
import { baseBuildConfig } from '../../scripts/modern.base.config';
3-
44
export default defineConfig({
55
...baseBuildConfig,
66
buildConfig: [
@@ -25,7 +25,19 @@ export default defineConfig({
2525
// because esbuild will transform `import.meta`.
2626
esbuildOptions: (options) => {
2727
options.target = undefined;
28-
return options;
28+
29+
let { inject } = options;
30+
const filepath = path.join(__dirname, 'shims.js');
31+
if (inject) {
32+
inject.push(filepath);
33+
} else {
34+
inject = [filepath];
35+
}
36+
37+
return {
38+
...options,
39+
inject,
40+
};
2941
},
3042
},
3143
],

packages/core/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,24 @@
5858
"@swc/helpers": "0.5.3",
5959
"core-js": "~3.36.0",
6060
"html-webpack-plugin": "npm:[email protected]",
61-
"postcss": "^8.4.38",
62-
"source-map": "0.5.7"
61+
"postcss": "^8.4.38"
6362
},
6463
"devDependencies": {
6564
"@types/node": "18.x",
6665
"@types/on-finished": "2.3.4",
6766
"@types/ws": "^8.5.10",
6867
"commander": "^12.0.0",
6968
"connect-history-api-fallback": "^2.0.0",
70-
"rspack-manifest-plugin": "5.0.0",
7169
"dotenv": "16.4.5",
7270
"dotenv-expand": "11.0.6",
7371
"http-compression": "1.0.19",
7472
"launch-editor-middleware": "^2.6.1",
7573
"on-finished": "2.4.1",
7674
"open": "^8.4.0",
7775
"prebundle": "1.1.0",
76+
"rspack-manifest-plugin": "5.0.0",
7877
"sirv": "^2.0.4",
78+
"source-map-js": "^1.2.0",
7979
"typescript": "^5.4.2",
8080
"webpack": "^5.91.0",
8181
"webpack-dev-middleware": "7.2.1",

packages/core/prebundle.config.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ export default {
1919
'ws',
2020
'on-finished',
2121
'rspack-manifest-plugin',
22+
{
23+
name: 'source-map-js',
24+
ignoreDts: true,
25+
},
2226
{
2327
name: 'launch-editor-middleware',
2428
ignoreDts: true,

packages/core/shims.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
globalThis.__dirname = new URL('./hmr', import.meta.url).pathname;

packages/core/src/client/findSourceMap.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// @ts-expect-error
2-
import { SourceMapConsumer } from 'source-map';
1+
// @ts-ignore
2+
import { SourceMapConsumer } from '../../compiled/source-map-js';
33

44
const fetchContent = (url: string) => fetch(url).then((r) => r.text());
55

pnpm-lock.yaml

Lines changed: 3 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)