Skip to content

Commit 746d9bb

Browse files
authored
Create React App v2 support (codesandbox#1124)
Adds a check to the React template for v2, if it is indeed v2 it will add: - CSS Modules + Sass (+module) versions of the transpilers. - Babel 7 transpiler with `env` and `react` presets and `babel-plugin-macros` plugin (am I missing anything?), we preload `babel-plugin-macros` in the transpiler. - A browser compatible `svgr-loader` which along with default export of file public path will also export `ReactComponent`. Along with this update I improved how our workers load to prefer hot workers over cold ones. This has a speed improvement for React since the babel worker now needs all project files for React (because of `macros`) and loading takes a while when the worker is cold. I also add a prebundled `@babel/runtime` for efficiency, I removed the prebundled `babel-runtime` in favor of dynamically downloading/loading it using the bundler. It turns out you never need all files for `babel-runtime` and shipping it with the bundler only increases parse/download time without being of much use. Note to self, release server `b475c4e` with this. Test sandbox: http://pr1124.cs.lbogdan.tk/s/z3rwnzm6p4
1 parent 93808ad commit 746d9bb

File tree

256 files changed

+654
-1121
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

256 files changed

+654
-1121
lines changed

packages/app/config/polyfills.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,17 @@ require('whatwg-fetch');
1212
// Object.assign() is commonly used with React.
1313
// It will use the native implementation if it's present and isn't buggy.
1414
Object.assign = require('object-assign');
15+
16+
window.cosmiconfig = {};
17+
window.prettier = {};
18+
window.jsdom = {
19+
JSDOM: {
20+
fragment(htmlString) {
21+
const div = document.createElement('div');
22+
div.innerHTML = htmlString.trim();
23+
24+
// Change this to div.childNodes to support multiple top-level nodes
25+
return div;
26+
},
27+
},
28+
};

packages/app/config/webpack.common.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ module.exports = {
103103
exclude: [
104104
/eslint\.4\.1\.0\.min\.js$/,
105105
/typescriptServices\.js$/,
106-
new RegExp(`babel-runtime${sepRe}`),
106+
/\.no-webpack\./,
107107
],
108108
loader: 'happypack/loader',
109109
},
@@ -210,6 +210,15 @@ module.exports = {
210210
replace: `throw new Error('module assert not found')`,
211211
},
212212
},
213+
// Remove dynamic require in jest circus
214+
{
215+
test: /babel-plugin-macros/,
216+
loader: 'string-replace-loader',
217+
options: {
218+
search: `_require(`,
219+
replace: `self.require(`,
220+
},
221+
},
213222
// "postcss" loader applies autoprefixer to our CSS.
214223
// "css" loader resolves paths in CSS and adds assets as dependencies.
215224
// "style" loader turns CSS into JS modules that inject <style> tags.
@@ -266,7 +275,7 @@ module.exports = {
266275
},
267276

268277
// To make jsonlint work
269-
externals: ['file', 'system'],
278+
externals: ['file', 'system', 'jsdom', 'prettier', 'cosmiconfig'],
270279

271280
resolve: {
272281
mainFields: ['browser', 'module', 'jsnext:main', 'main'],

packages/app/config/webpack.prod.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ module.exports = merge(commonConfig, {
5555

5656
splitChunks: {
5757
chunks: 'all',
58+
maxInitialRequests: 20, // for HTTP2
59+
maxAsyncRequests: 20, // for HTTP2
5860
name(module, chunks, cacheGroup) {
5961
const name = normalize(module, chunks, cacheGroup);
6062

packages/app/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"gzip-size": "3.0.0",
6060
"happypack": "^5.0.0",
6161
"html-loader": "^0.5.5",
62-
"html-webpack-plugin": "^3.2.0",
62+
"html-webpack-plugin": "^4.0.0-beta.1",
6363
"http-proxy-middleware": "^0.17.3",
6464
"husky": "^0.14.3",
6565
"jest": "^21.2.1",
@@ -101,6 +101,7 @@
101101
"@cerebral/http": "^4.0.0",
102102
"@cerebral/mobx-state-tree": "^3.0.0",
103103
"@emmetio/codemirror-plugin": "^0.3.5",
104+
"@svgr/core": "^2.4.1",
104105
"@vue/babel-preset-app": "^3.0.1",
105106
"apollo-boost": "^0.1.7",
106107
"apollo-link-batch-http": "^1.2.2",

packages/app/src/sandbox/compile.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ const BABEL_DEPENDENCIES = [
109109
// system in the future
110110
const PREINSTALLED_DEPENDENCIES = [
111111
'node-lib-browser',
112-
'babel-runtime',
113112
'react-scripts',
114113
'react-scripts-ts',
115114
'parcel-bundler',
115+
'@babel/runtime',
116116
'babel-plugin-check-es2015-constants',
117117
'babel-plugin-external-helpers',
118118
'babel-plugin-inline-replace-variables',
@@ -265,6 +265,11 @@ function getDependencies(parsedPackage, templateDefinition, configurations) {
265265
};
266266
}
267267

268+
// Always include this, because most sandboxes need this with babel6 and the
269+
// packager will only include the package.json for it.
270+
returnedDependencies['babel-runtime'] =
271+
returnedDependencies['babel-runtime'] || '6.26.0';
272+
268273
preinstalledDependencies.forEach(dep => {
269274
if (returnedDependencies[dep]) {
270275
delete returnedDependencies[dep];

packages/app/src/sandbox/eval/loaders/@babel-runtime.no-webpack.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/app/src/sandbox/eval/loaders/babel-runtime/core-js.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

packages/app/src/sandbox/eval/loaders/babel-runtime/core-js/array/concat.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/app/src/sandbox/eval/loaders/babel-runtime/core-js/array/copy-within.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/app/src/sandbox/eval/loaders/babel-runtime/core-js/array/entries.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)