Skip to content

Commit 56e59a0

Browse files
authored
Upgrade Sandpack and support custom root URLs (codesandbox#2489)
* Update dependencies * Make sandpack and react-sandpack work standalone
1 parent e6648ae commit 56e59a0

File tree

23 files changed

+19361
-53
lines changed

23 files changed

+19361
-53
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
**/cra-files/*.*
22
**/eslint-lint.js
3+
**/stories/*.*

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
"packages/homepage",
1414
"packages/common",
1515
"packages/codesandbox-api",
16-
"packages/sandpack",
17-
"packages/react-sandpack",
1816
"packages/node-services",
1917
"packages/sandbox-hooks",
2018
"packages/sse-hooks",
@@ -39,9 +37,9 @@
3937
"build:embed": "lerna run build:embed --scope app --stream && gulp",
4038
"build:prod": "cross-env NODE_OPTIONS=\"--max-old-space-size=4096\" lerna run build --scope homepage --stream && lerna run build --scope app --stream && lerna run copy-assets --scope app --stream",
4139
"commit": "concurrently \"yarn typecheck\" \"yarn lint\" && git commit -m",
40+
"postinstall": "yarn lerna run install-dependencies --stream && opencollective postinstall",
4241
"contributors:add": "all-contributors add",
4342
"contributors:generate": "all-contributors generate",
44-
"postinstall": "yarn lerna run install-dependencies --scope vscode-textmate --scope codesandbox-browserfs --scope sse-loading-screen --stream && opencollective postinstall",
4543
"lint": "lerna run lint --stream",
4644
"now-build": "yarn build:deps && lerna run build:storybook --scope @codesandbox/common",
4745
"start": "yarn build:deps && lerna run start --scope @codesandbox/common --scope app --parallel",

packages/app/config/build.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
const isDev = process.env.NODE_ENV === 'development';
2+
const { SANDBOX_ONLY } = process.env;
23
const staticAssets = [
3-
{
4+
!SANDBOX_ONLY && {
45
from: 'standalone-packages/vscode-editor/release/min/vs',
56
to: 'public/vscode24/vs',
67
},
7-
{
8+
!SANDBOX_ONLY && {
89
from: 'standalone-packages/vscode-extensions/out',
910
to: 'public/vscode-extensions/v10',
1011
},
11-
{
12+
!SANDBOX_ONLY && {
1213
from: 'node_modules/onigasm/lib/onigasm.wasm',
1314
to: 'public/onigasm/2.2.1/onigasm.wasm',
1415
},
15-
{
16+
!SANDBOX_ONLY && {
1617
from:
1718
'standalone-packages/vscode-textmate/node_modules/onigasm/lib/onigasm.wasm',
1819
to: 'public/onigasm/2.1.0/onigasm.wasm',
1920
},
20-
{
21+
!SANDBOX_ONLY && {
2122
from: 'node_modules/monaco-vue/release/min',
2223
to: 'public/14/vs/language/vue',
2324
},
24-
{
25+
!SANDBOX_ONLY && {
2526
from: 'standalone-packages/monaco-editor/release/min/vs',
2627
to: 'public/14/vs',
2728
},
@@ -56,7 +57,7 @@ const staticAssets = [
5657
: 'standalone-packages/codesandbox-browserfs/dist',
5758
to: 'static/browserfs3',
5859
},
59-
];
60+
].filter(Boolean);
6061

6162
module.exports = {
6263
staticAssets,

packages/app/config/webpack.common.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
const webpack = require('webpack');
33
const path = require('path');
44
const fs = require('fs');
5-
const paths = require('./paths');
65
const HtmlWebpackPlugin = require('html-webpack-plugin');
76
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
87
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
98
const threadLoader = require('thread-loader');
10-
const WatchMissingNodeModulesPlugin = require('../scripts/utils/WatchMissingNodeModulesPlugin');
119
const env = require('@codesandbox/common/lib/config/env');
1210
const getHost = require('@codesandbox/common/lib/utils/host');
1311
const postcssNormalize = require('postcss-normalize');
12+
const WatchMissingNodeModulesPlugin = require('../scripts/utils/WatchMissingNodeModulesPlugin');
13+
const paths = require('./paths');
1414

1515
const babelDev = require('./babel.dev');
1616
const babelProd = require('./babel.prod');
@@ -426,7 +426,7 @@ module.exports = {
426426
new HtmlWebpackPlugin({
427427
inject: true,
428428
chunks: ['sandbox-startup', 'vendors~sandbox', 'sandbox'],
429-
filename: 'frame.html',
429+
filename: 'index.html',
430430
template: paths.sandboxHtml,
431431
minify: __PROD__ && {
432432
removeComments: true,

packages/app/config/webpack.prod.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,9 @@ module.exports = merge(commonConfig, {
227227
minify: true,
228228
// For unknown URLs, fallback to the index page
229229
navigateFallback: 'https://new.codesandbox.io/frame.html',
230-
staticFileGlobs: ['www/frame.html'],
230+
staticFileGlobs: process.env.SANDBOX_ONLY
231+
? ['www/index.html']
232+
: ['www/frame.html'],
231233
stripPrefix: 'www/',
232234
// Ignores URLs starting from /__ (useful for Firebase):
233235
// https://github.com/facebookincubator/create-react-app/issues/2237#issuecomment-302693219

packages/app/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"build": "cross-env NODE_ENV=production NODE_OPTIONS=\"--max-old-space-size=4096\" node scripts/build.js",
1313
"build:clean": "rimraf www",
1414
"build:embed": "cross-env NODE_ENV=production webpack --config config/webpack.embed.js",
15-
"build:sandbox": "cross-env NODE_ENV=production SANDBOX_ONLY=true node scripts/build.js",
15+
"build:sandbox": "cross-env NODE_ENV=production SANDBOX_ONLY=true node scripts/build.js && yarn copy-assets",
16+
"build:sandpack-sandbox": "cross-env NODE_ENV=production SANDPACK=true SANDBOX_ONLY=true node scripts/build.js && cross-env SANDBOX_ONLY=true yarn copy-assets",
1617
"copy-assets": "cross-env NODE_ENV=production node scripts/copy-assets.js",
1718
"integrations:start": "docker run -v $(pwd):/app/ -it codesandbox/test yarn start:test",
1819
"lint": "npm run lint:app && npm run lint:embed && npm run lint:sandbox",
@@ -22,6 +23,7 @@
2223
"start": "cross-env LOCAL_SERVER=1 LOCAL_DEV=1 NODE_OPTIONS=\"--max-old-space-size=4096\" node scripts/start.js",
2324
"start:dev_api": "node scripts/start.js",
2425
"start:sandbox": "cross-env SANDBOX_ONLY=true node scripts/start.js",
26+
"start:sandpack-sandbox": "cross-env SANDPACK=true LOCAL_SERVER=1 SANDBOX_ONLY=true node scripts/start.js",
2527
"start:test": "cross-env LOCAL_SERVER=1 SANDBOX_ONLY=true node scripts/start.js",
2628
"test": "jest --env=jsdom",
2729
"test:integrations": "jest --config integration-tests/jest.config.json --maxWorkers=2",
@@ -98,7 +100,7 @@
98100
"cerebral": "^4.0.0",
99101
"circular-json": "^0.4.0",
100102
"codemirror": "^5.27.4",
101-
"codesandbox-api": "^0.0.22",
103+
"codesandbox-api": "0.0.23",
102104
"codesandbox-import-utils": "2.1.2",
103105
"color": "^0.11.4",
104106
"compare-versions": "^3.1.0",

packages/app/scripts/copy-assets.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,35 @@ const fs = require('fs-extra');
33
const path = require('path');
44
const { staticAssets } = require('../config/build');
55

6+
const { SANDBOX_ONLY } = process.env;
7+
68
const assets = [
79
...staticAssets,
810
{
911
from: 'packages/app/www',
1012
to: '',
1113
},
12-
{
14+
!SANDBOX_ONLY && {
1315
from: 'packages/homepage/public',
1416
to: '',
1517
},
16-
{
18+
!SANDBOX_ONLY && {
1719
from: 'standalone-packages/monaco-editor/release/min/vs',
1820
to: 'public/14/vs',
1921
},
2022
{
2123
from: 'standalone-packages/codesandbox-browserfs/dist',
2224
to: 'static/browserfs2',
2325
},
24-
{
26+
!SANDBOX_ONLY && {
2527
from: 'standalone-packages/vscode-editor/release/min/vs',
2628
to: 'public/vscode22/vs',
2729
},
2830
{
2931
from: 'packages/app/public',
3032
to: '',
3133
},
32-
];
34+
].filter(Boolean);
3335

3436
const rootPath = path.resolve(__dirname, '../../..');
3537
const buildPath = path.resolve(rootPath, 'www');

packages/codesandbox-api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codesandbox-api",
3-
"version": "0.0.22",
3+
"version": "0.0.23",
44
"description": "",
55
"keywords": [],
66
"repository": {

packages/common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"@tippy.js/react": "^2.1.1",
4949
"babel-plugin-preval": "^3.0.1",
5050
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
51-
"codesandbox-api": "^0.0.22",
51+
"codesandbox-api": "0.0.23",
5252
"color": "0.11.4",
5353
"date-fns": "^2.0.0",
5454
"dot-object": "1.9.0",

packages/common/src/utils/host.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
const IS_LOCAL_SERVER = Boolean(JSON.stringify(process.env.LOCAL_SERVER));
22

33
export default () => {
4+
if ('SANDPACK' in process.env) {
5+
return '';
6+
}
7+
48
if (IS_LOCAL_SERVER) {
59
return 'http://localhost:3000';
610
}

0 commit comments

Comments
 (0)