Skip to content

Commit

Permalink
fix react cjs resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Sep 30, 2021
1 parent ef46d0c commit 8af2ac2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
1 change: 0 additions & 1 deletion scripts/build-react.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { BuildOptions, submodulePackageJson, submodulePath } from './utils';
import { join } from 'path';
import type { RollupOptions } from 'rollup';
import { readJson, writeJson } from 'fs-extra';

export function buildReact(opts: BuildOptions): RollupOptions {
return {
Expand Down
9 changes: 4 additions & 5 deletions scripts/build-service-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from './utils';
import { join } from 'path';
import { minifyPlugin } from './minify';
import { writeFile } from 'fs-extra';
import { ensureDir, writeFile } from 'fs-extra';
import { webWorkerBlobUrlPlugin } from './build-web-worker';

export function buildServiceWorker(opts: BuildOptions): RollupOptions {
Expand Down Expand Up @@ -65,10 +65,9 @@ async function buildSandboxServiceWorker(opts: BuildOptions, msgType: MessageTyp

let sandboxHtml: string;
if (debug) {
await writeFile(
join(opts.buildLibDir, 'debug', `partytown-sandbox-${msgType}.js`),
sandboxJsCode
);
const buildLibDebugDir = join(opts.buildLibDir, 'debug');
await ensureDir(buildLibDebugDir);
await writeFile(join(buildLibDebugDir, `partytown-sandbox-${msgType}.js`), sandboxJsCode);
sandboxHtml = `<!DOCTYPE html><html><head><meta charset="utf-8"><script src="./partytown-sandbox-${msgType}.js"></script></head></html>`;
} else {
sandboxHtml = `<!DOCTYPE html><html><head><meta charset="utf-8"><script type="module">${sandboxJsCode}</script></head></html>`;
Expand Down
5 changes: 2 additions & 3 deletions scripts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import gzipSize from 'gzip-size';
import { basename, join } from 'path';
import {
copy,
emptyDir,
ensureDir,
readdirSync,
readFileSync,
Expand Down Expand Up @@ -59,7 +58,7 @@ export function submodulePath(moduleId: string, submodulePath: string): Plugin {
if (id === moduleId) {
return {
external: true,
id: submodulePath + '.MODULE_EXT',
id: submodulePath + '._MODULE_EXT_',
};
}
return null;
Expand All @@ -69,7 +68,7 @@ export function submodulePath(moduleId: string, submodulePath: string): Plugin {
for (const f in bundle) {
const b = bundle[f];
if (b.type === 'chunk') {
b.code = b.code.replace(`MODULE_EXT`, ext);
b.code = b.code.replace(/_MODULE_EXT_/g, ext);
}
}
},
Expand Down

1 comment on commit 8af2ac2

@vercel
Copy link

@vercel vercel bot commented on 8af2ac2 Sep 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.