Skip to content

Commit 8713bb1

Browse files
committed
Only sync files if explicitly needed by React
1 parent 0ca2602 commit 8713bb1

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

packages/app/src/sandbox/eval/transpilers/babel/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ class BabelTranspiler extends WorkerTranspiler {
8585
const isV7 =
8686
loaderContext.options.isV7 || isBabel7(dependencies, devDependencies);
8787

88+
const hasMacros = Object.keys(dependencies).some(
89+
d => d.indexOf('macro') > -1
90+
);
91+
8892
const babelConfig = getBabelConfig(
8993
foundConfig || loaderOptions.config,
9094
loaderOptions,
@@ -104,6 +108,7 @@ class BabelTranspiler extends WorkerTranspiler {
104108
configs.babelTranspiler.parsed,
105109
sandboxOptions: configs && configs.sandbox && configs.sandbox.parsed,
106110
version: isV7 ? 7 : 6,
111+
hasMacros,
107112
},
108113
loaderContext._module.getId(),
109114
loaderContext,

packages/app/src/sandbox/eval/transpilers/babel/worker/babel-worker.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ async function installPreset(Babel, BFSRequire, preset, currentPath, isV7) {
159159

160160
self.importScripts(
161161
process.env.NODE_ENV === 'development'
162-
? `${process.env.CODESANDBOX_HOST || ''}/static/js/babel.6.26.js`
163-
: `${process.env.CODESANDBOX_HOST || ''}/static/js/babel.6.26.min.js`
162+
? `${process.env.CODESANDBOX_HOST || ''}/static/js/babel.7.00-1.min.js`
163+
: `${process.env.CODESANDBOX_HOST || ''}/static/js/babel.7.00-1.min.js`
164164
);
165165

166166
self.postMessage('ready');
@@ -239,6 +239,7 @@ self.addEventListener('message', async event => {
239239
loaderOptions,
240240
version,
241241
type,
242+
hasMacros,
242243
} = event.data;
243244

244245
if (type !== 'compile') {
@@ -253,12 +254,11 @@ self.addEventListener('message', async event => {
253254

254255
if (babelUrl || babelEnvUrl) {
255256
loadCustomTranspiler(babelUrl, babelEnvUrl);
256-
} else if (version === 7) {
257+
} else if (version !== 7) {
257258
loadCustomTranspiler(
258259
process.env.NODE_ENV === 'development'
259-
? `${process.env.CODESANDBOX_HOST || ''}/static/js/babel.7.00-1.min.js`
260-
: `${process.env.CODESANDBOX_HOST ||
261-
''}/static/js/babel.7.00-1.min.js`
260+
? `${process.env.CODESANDBOX_HOST || ''}/static/js/babel.6.26.js`
261+
: `${process.env.CODESANDBOX_HOST || ''}/static/js/babel.6.26.min.js`
262262
);
263263
}
264264

@@ -321,7 +321,9 @@ self.addEventListener('message', async event => {
321321
flattenedPlugins.indexOf('babel-plugin-macros') > -1 &&
322322
Object.keys(Babel.availablePlugins).indexOf('babel-plugin-macros') === -1
323323
) {
324-
await waitForFs();
324+
if (hasMacros) {
325+
await waitForFs();
326+
}
325327

326328
Babel.registerPlugin('babel-plugin-macros', macrosPlugin);
327329
}

0 commit comments

Comments
 (0)