Skip to content

Commit 8ebede2

Browse files
author
Ives van Hoorne
committed
Remove babel-runtime
1 parent 54893b3 commit 8ebede2

File tree

5 files changed

+43
-52
lines changed

5 files changed

+43
-52
lines changed

packages/app/config/webpack.common.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,13 @@ module.exports = {
384384
),
385385

386386
...(SANDBOX_ONLY
387-
? []
387+
? [
388+
new webpack.optimize.CommonsChunkPlugin({
389+
async: true,
390+
children: true,
391+
minChunks: 2,
392+
}),
393+
]
388394
: [
389395
// We first create a common chunk between embed and app, to share components
390396
// and dependencies.

packages/app/src/sandbox/eval/loaders/dependency-resolver.js

+12-30
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,21 @@ import DependencyNotFoundError from '../../errors/dependency-not-found-error';
77
* @param {Object} externals
88
* @returns
99
*/
10-
export default function getDependency(
11-
dependencyPath: string,
12-
externals: { [key: string]: string }
13-
) {
14-
// This polyfill is included by default in the sandbox, no external dependency needed.
15-
// This is also included in CRA by default, so we keep compatability with
16-
// CRA.
17-
if (dependencyPath.startsWith('babel-runtime')) {
18-
// eslint-disable-next-line global-require, import/no-dynamic-require
19-
return require(`./babel-runtime${dependencyPath.replace(
20-
'babel-runtime',
21-
''
22-
)}`);
23-
}
10+
export default function getDependency(dependencyPath: string) {
11+
// // This polyfill is included by default in the sandbox, no external dependency needed.
12+
// // This is also included in CRA by default, so we keep compatability with
13+
// // CRA.
14+
// if (dependencyPath.startsWith('babel-runtime')) {
15+
// // eslint-disable-next-line global-require, import/no-dynamic-require
16+
// return require(`./babel-runtime${dependencyPath.replace(
17+
// 'babel-runtime',
18+
// ''
19+
// )}`);
20+
// }
2421

2522
if (dependencyPath === 'codesandbox-api') {
2623
return require('codesandbox-api');
2724
}
28-
const dependencyModule =
29-
externals[dependencyPath] || externals[`${dependencyPath}.js`];
30-
if (dependencyModule) {
31-
const idMatch = dependencyModule.match(/dll_bundle\((\d+)\)/);
32-
if (idMatch && idMatch[1]) {
33-
try {
34-
return window.dll_bundle(idMatch[1]);
35-
} catch (e) {
36-
if (window.dll_bundle) {
37-
// Delete the cache of the throwing dependency
38-
delete window.dll_bundle.c[idMatch[1]];
39-
}
40-
throw e;
41-
}
42-
}
43-
}
25+
4426
throw new DependencyNotFoundError(dependencyPath);
4527
}

packages/app/src/sandbox/eval/transpiled-module.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -746,10 +746,7 @@ export default class TranspiledModule {
746746
// eslint-disable-line no-unused-vars
747747
if (/^(\w|@\w)/.test(aliasedPath) && !aliasedPath.includes('!')) {
748748
// So it must be a dependency
749-
if (
750-
aliasedPath.startsWith('babel-runtime') ||
751-
aliasedPath.startsWith('codesandbox-api')
752-
)
749+
if (aliasedPath.startsWith('codesandbox-api'))
753750
return resolveDependency(aliasedPath, manager.externals);
754751
}
755752

packages/app/src/sandbox/eval/transpilers/vue/selector/index.js

+3-17
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,15 @@
11
// @flow
2-
import path from 'path';
3-
42
import Transpiler from '../../';
53
import { type LoaderContext } from '../../../transpiled-module';
64

7-
import parse from '../parser';
8-
95
class VueSelector extends Transpiler {
106
constructor() {
117
super('vue-selector');
128
}
139
doTranspilation(content: string, loaderContext: LoaderContext) {
14-
const query = loaderContext.options;
15-
const context = query.context;
16-
let filename = path.basename(loaderContext.path);
17-
filename =
18-
filename.substring(0, filename.lastIndexOf(path.extname(filename))) +
19-
'.vue';
20-
const sourceRoot = path.dirname(path.relative(context, loaderContext.path));
21-
const parts = parse(content, filename, false, sourceRoot, query.bustCache);
22-
let part = parts[query.type];
23-
if (Array.isArray(part)) {
24-
part = part[query.index];
25-
}
26-
return Promise.resolve({ transpiledCode: part.content });
10+
return import(/* webpackChunkName: 'vue-selector' */ './loader').then(
11+
loader => loader.default(content, loaderContext)
12+
);
2713
}
2814
}
2915

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import path from 'path';
2+
import parse from '../parser';
3+
4+
import { type LoaderContext } from '../../../transpiled-module';
5+
6+
export default function(code: string, loaderContext: LoaderContext) {
7+
const query = loaderContext.options;
8+
const context = query.context;
9+
let filename = path.basename(loaderContext.path);
10+
filename =
11+
filename.substring(0, filename.lastIndexOf(path.extname(filename))) +
12+
'.vue';
13+
const sourceRoot = path.dirname(path.relative(context, loaderContext.path));
14+
const parts = parse(code, filename, false, sourceRoot, query.bustCache);
15+
let part = parts[query.type];
16+
if (Array.isArray(part)) {
17+
part = part[query.index];
18+
}
19+
return Promise.resolve({ transpiledCode: part.content });
20+
}

0 commit comments

Comments
 (0)