Skip to content

Commit

Permalink
chore: Replace it with source-map-js and prebundle it
Browse files Browse the repository at this point in the history
  • Loading branch information
nanianlisao committed May 17, 2024
1 parent 075c2bb commit 82b06ba
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 16 deletions.
16 changes: 14 additions & 2 deletions packages/core/modern.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'node:path';
import { defineConfig } from '@modern-js/module-tools';
import { baseBuildConfig } from '../../scripts/modern.base.config';

export default defineConfig({
...baseBuildConfig,
buildConfig: [
Expand All @@ -25,7 +25,19 @@ export default defineConfig({
// because esbuild will transform `import.meta`.
esbuildOptions: (options) => {
options.target = undefined;
return options;

let { inject } = options;
const filepath = path.join(__dirname, 'shims.js');
if (inject) {
inject.push(filepath);
} else {
inject = [filepath];
}

return {
...options,
inject,
};
},
},
],
Expand Down
6 changes: 3 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,24 @@
"@swc/helpers": "0.5.3",
"core-js": "~3.36.0",
"html-webpack-plugin": "npm:[email protected]",
"postcss": "^8.4.38",
"source-map": "0.5.7"
"postcss": "^8.4.38"
},
"devDependencies": {
"@types/node": "18.x",
"@types/on-finished": "2.3.4",
"@types/ws": "^8.5.10",
"commander": "^12.0.0",
"connect-history-api-fallback": "^2.0.0",
"rspack-manifest-plugin": "5.0.0",
"dotenv": "16.4.5",
"dotenv-expand": "11.0.6",
"http-compression": "1.0.19",
"launch-editor-middleware": "^2.6.1",
"on-finished": "2.4.1",
"open": "^8.4.0",
"prebundle": "1.1.0",
"rspack-manifest-plugin": "5.0.0",
"sirv": "^2.0.4",
"source-map-js": "^1.2.0",
"typescript": "^5.4.2",
"webpack": "^5.91.0",
"webpack-dev-middleware": "7.2.1",
Expand Down
4 changes: 4 additions & 0 deletions packages/core/prebundle.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export default {
'ws',
'on-finished',
'rspack-manifest-plugin',
{
name: 'source-map-js',
ignoreDts: true,
},
{
name: 'launch-editor-middleware',
ignoreDts: true,
Expand Down
1 change: 1 addition & 0 deletions packages/core/shims.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
globalThis.__dirname = new URL('./hmr', import.meta.url).pathname;
4 changes: 2 additions & 2 deletions packages/core/src/client/findSourceMap.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @ts-expect-error
import { SourceMapConsumer } from 'source-map';
// @ts-ignore
import { SourceMapConsumer } from '../../compiled/source-map-js';

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

Expand Down
12 changes: 3 additions & 9 deletions pnpm-lock.yaml

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

0 comments on commit 82b06ba

Please sign in to comment.