Skip to content

Remove babel-polyfill from sandbox #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion config/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ module.exports = {
entry: {
app: [require.resolve('./polyfills'), path.join(paths.appSrc, 'index.js')],
sandbox: [
require.resolve('babel-polyfill'),
require.resolve('./polyfills'),
path.join(paths.sandboxSrc, 'index.js'),
],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-latest": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-runtime": "^6.20.0",
"babel-runtime": "^6.26.0",
"babili-webpack-plugin": "^0.1.1",
"buffer-loader": "^0.0.1",
"case-sensitive-paths-webpack-plugin": "^2.0.0",
Expand Down
7 changes: 7 additions & 0 deletions src/sandbox/eval/loaders/dependency-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ export default function getDependency(
dependencyPath: string,
externals: { [key: string]: string }
) {
// This polyfill is included by default in the sandbox, no external dependency needed.
// This is also included in CRA by default, so we keep compatability with
// CRA.
if (dependencyPath === 'babel-runtime/regenerator') {
return require('babel-runtime/regenerator'); // eslint-disable-line global-require
}

const dependencyModule =
externals[dependencyPath] || externals[`${dependencyPath}.js`];
if (dependencyModule) {
Expand Down
8 changes: 7 additions & 1 deletion src/sandbox/eval/presets/create-react-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ import babelTranspiler from '../../transpilers/babel';
import jsonTranspiler from '../../transpilers/json';
import rawTranspiler from '../../transpilers/raw';

const preset = new Preset('create-react-app');
const preset = new Preset('create-react-app', [
'web.js',
'js',
'json',
'web.jsx',
'jsx',
]);

preset.registerTranspiler(module => /\.css$/.test(module.title), [
{ transpiler: stylesTranspiler },
Expand Down
16 changes: 16 additions & 0 deletions src/sandbox/eval/transpilers/babel/babel-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@ const DEFAULT_BABEL_CONFIG = {
'transform-object-rest-spread',
'transform-decorators-legacy',
'transform-class-properties',
// Polyfills the runtime needed for async/await and generators
[
'transform-runtime',
{
helpers: false,
polyfill: false,
regenerator: true,
},
],
[
'transform-regenerator',
{
// Async functions are converted to generators by babel-preset-env
async: false,
},
],
],
};

Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1551,7 +1551,7 @@ [email protected]:
core-js "^2.4.0"
regenerator-runtime "^0.10.0"

[email protected], babel-runtime@^6.18.0, babel-runtime@^6.2.0, babel-runtime@^6.20.0, babel-runtime@^6.22.0:
[email protected], babel-runtime@^6.18.0, babel-runtime@^6.2.0, babel-runtime@^6.22.0:
version "6.25.0"
resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.25.0.tgz#33b98eaa5d482bb01a8d1aa6b437ad2b01aec41c"
dependencies:
Expand Down