Skip to content

Commit 995a98a

Browse files
lbogdanCompuIves
authored andcommitted
Build improvements (#2076)
* [WIP] Build improvements. * Fix production build. * Extract static assets to config/build.js and use them in both dev and prod scripts. * Cleanup. * Update yarn.lock. * Update standalone-packages/vscode-textmate/package-lock.json. * Bump CircleCI cache keys version. * Revert "Update standalone-packages/vscode-textmate/package-lock.json." * Small improvements. * Update webpack to latest 4.35.0. * CodeMirror: remove auto-complete, so we're not bundling tern. * Remove unneeded gulp tasks. * Update webpack-dev-server to latest 3.7.2 and remove unused webpack-dev-middleware. * Show the updated module which triggers re-compiling. * Don't use thread-loader while linting. * Extract tern dep to codesandbox-deps and re-add CodeMirror bits. * Disable console clearing on Windows by default and - use CLEAR environment variable to override default behavior.
1 parent a102c84 commit 995a98a

File tree

15 files changed

+1821
-664
lines changed

15 files changed

+1821
-664
lines changed

Diff for: .circleci/config.yml

+14-14
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ version: 2.1
66

77
aliases:
88
- &restore_repo_cache
9-
key: v20-repo-{{ .Environment.CIRCLE_SHA1 }}
9+
key: v18-repo-{{ .Environment.CIRCLE_SHA1 }}
1010

1111
- &save_repo_cache
12-
key: v20-repo-{{ .Environment.CIRCLE_SHA1 }}
12+
key: v18-repo-{{ .Environment.CIRCLE_SHA1 }}
1313
paths:
1414
- ~/codesandbox-client
1515

1616
- &restore_deps_cache
1717
keys:
18-
- v20-dependency-cache-{{ .Branch }}-{{ checksum "yarn.lock" }}
19-
- v20-dependency-cache-{{ .Branch }}
20-
- v20-dependency-cache
18+
- v18-dependency-cache-{{ .Branch }}-{{ checksum "yarn.lock" }}
19+
- v18-dependency-cache-{{ .Branch }}
20+
- v18-dependency-cache
2121

2222
- &save_deps_cache
23-
key: v20-dependency-cache-{{ .Branch }}-{{ checksum "yarn.lock" }}
23+
key: v18-dependency-cache-{{ .Branch }}-{{ checksum "yarn.lock" }}
2424
paths:
2525
- node_modules
2626
- packages/app/node_modules
@@ -39,29 +39,29 @@ aliases:
3939

4040
- &restore_standalone_deps_cache
4141
keys:
42-
- v20-standalone-dependency-cache-{{ .Branch }}-{{ checksum "standalone-packages/codesandbox-browserfs/yarn.lock" }}
43-
- v20-standalone-dependency-cache-{{ .Branch }}
44-
- v20-standalone-dependency-cache
42+
- v18-standalone-dependency-cache-{{ .Branch }}-{{ checksum "standalone-packages/codesandbox-browserfs/yarn.lock" }}
43+
- v18-standalone-dependency-cache-{{ .Branch }}
44+
- v18-standalone-dependency-cache
4545

4646
- &save_standalone_deps_cache
47-
key: v20-standalone-dependency-cache-{{ .Branch }}-{{ checksum "standalone-packages/codesandbox-browserfs/yarn.lock" }}
47+
key: v18-standalone-dependency-cache-{{ .Branch }}-{{ checksum "standalone-packages/codesandbox-browserfs/yarn.lock" }}
4848
paths:
4949
- standalone-packages/codesandbox-browserfs/node_modules
5050

5151
- &restore_prod_build_cache
52-
key: v20-prod-app-build-cache-master
52+
key: v18-prod-app-build-cache-master
5353

5454
- &restore_prod_cache
55-
key: v20-prod-build-cache-{{ .Environment.CIRCLE_BRANCH }}-{{ .Environment.CIRCLE_SHA1 }}
55+
key: v18-prod-build-cache-{{ .Environment.CIRCLE_BRANCH }}-{{ .Environment.CIRCLE_SHA1 }}
5656

5757
- &save_prod_app_cache
58-
key: v20-prod-app-build-cache-{{ .Environment.CIRCLE_BRANCH }}-{{ .Environment.CIRCLE_SHA1 }}
58+
key: v18-prod-app-build-cache-{{ .Environment.CIRCLE_BRANCH }}-{{ .Environment.CIRCLE_SHA1 }}
5959
paths:
6060
- ./packages/app/www
6161
- ./packages/homepage/.cache
6262

6363
- &save_prod_cache
64-
key: v20-prod-build-cache-{{ .Environment.CIRCLE_BRANCH }}-{{ .Environment.CIRCLE_SHA1 }}
64+
key: v18-prod-build-cache-{{ .Environment.CIRCLE_BRANCH }}-{{ .Environment.CIRCLE_SHA1 }}
6565
paths:
6666
- ./www
6767

Diff for: Gulpfile.js

-40
Original file line numberDiff line numberDiff line change
@@ -21,46 +21,6 @@ function rimraf(dir) {
2121
return cb => retry(cb);
2222
}
2323

24-
gulp.task('app', () =>
25-
gulp.src('packages/app/www/**/*').pipe(gulp.dest('www'))
26-
);
27-
28-
gulp.task('homepage', () =>
29-
gulp.src('packages/homepage/public/**/*').pipe(gulp.dest('www'))
30-
);
31-
32-
gulp.task('monaco', () =>
33-
gulp
34-
.src('standalone-packages/monaco-editor/release/min/vs/**/*')
35-
.pipe(gulp.dest('www/public/14/vs'))
36-
);
37-
38-
// Used for cases where HTML is cached
39-
gulp.task('old-browserfs', () =>
40-
gulp
41-
.src('standalone-packages/codesandbox-browserfs/dist/**/*')
42-
.pipe(gulp.dest('www/static/browserfs2'))
43-
);
44-
45-
gulp.task('old-vscode', () =>
46-
gulp
47-
.src('standalone-packages/vscode-editor/release/min/vs/**/*')
48-
.pipe(gulp.dest('www/public/vscode8/vs'))
49-
);
50-
51-
gulp.task('statics', () =>
52-
gulp.src('packages/app/public/**/*').pipe(gulp.dest('www'))
53-
);
54-
55-
gulp.task('default', [
56-
'app',
57-
'homepage',
58-
'statics',
59-
'monaco',
60-
'old-browserfs',
61-
'old-vscode',
62-
]);
63-
6424
gulp.task('clean-vscode', rimraf('standalone-packages/monaco-editor-core'));
6525

6626
gulp.task('prepare-vscode', ['clean-vscode'], () =>

Diff for: package.json

+14-10
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@
44
"license": "GPL-3.0",
55
"private": true,
66
"scripts": {
7-
"build": "NODE_OPTIONS=\"--max-old-space-size=4096\" yarn build:deps && yarn build:prod",
8-
"build:prod": "NODE_OPTIONS=\"--max-old-space-size=4096\" lerna run build --scope homepage --stream && lerna run build --scope app --stream && gulp",
7+
"build": "cross-env NODE_OPTIONS=\"--max-old-space-size=4096\" yarn build:deps && yarn build:prod",
8+
"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",
99
"build:embed": "lerna run build:embed --scope app --stream && gulp",
1010
"build:clean": "lerna run build:clean --scope app --scope homepage && rimraf www",
11-
"build:deps": "lerna run build:dev --scope codesandbox-api --scope @codesandbox/notifications && lerna run build:dev --scope @codesandbox/common && lerna run build:dev --scope vscode-textmate --scope codesandbox-browserfs --scope node-services && lerna run build:dev --scope sse-hooks",
11+
"build:deps": "lerna run build:dev --scope codesandbox-api --scope @codesandbox/notifications && lerna run build:dev --scope @codesandbox/common && lerna run build:dev --scope vscode-textmate --scope codesandbox-browserfs --scope node-services && lerna run build:dev --scope sse-hooks && lerna run build --scope codesandbox-deps",
1212
"build:common": "lerna run build:dev --scope @codesandbox/common --stream",
1313
"build:dynamic": "lerna run build --scope dynamic-pages --stream",
14-
"start": "yarn build:deps && lerna run start --scope app --stream",
14+
"start": "yarn build:deps && yarn start:fast",
1515
"start:overmind": "yarn build:deps && concurrently \"lerna run start --scope app --stream\" \"overmind-devtools\"",
16-
"start:fast": "lerna run start --scope app --stream",
17-
"start:vscode": "VSCODE=1 yarn start:fast & cd standalone-packages/monaco-editor && yarn simpleserver & cd standalone-packages/vscode && yarn watch",
16+
"start:fast": "cd packages/app && yarn start",
17+
"start:vscode": "cross-env VSCODE=1 yarn start:fast & cd standalone-packages/monaco-editor && yarn simpleserver & cd standalone-packages/vscode && yarn watch",
1818
"start:dynamic": "lerna run dev --scope dynamic-pages --stream",
1919
"start:common": "lerna run start --scope common --stream",
20-
"start:home": "lerna run start --scope homepage --stream",
20+
"start:home": "cd packages/homepage && yarn start",
2121
"start:test": "lerna run start:test --scope app --stream",
2222
"start:dev_api": "lerna run start:dev_api --scope app --stream",
2323
"test": "lerna run test --ignore codesandbox-browserfs",
2424
"test:integrations": "lerna exec --scope app --stream -- yarn test:integrations",
2525
"test:jest-lite": "lerna exec --scope app --stream -- yarn run test jest-lite --watch --coverage",
26-
"lint": "lerna run lint",
26+
"lint": "lerna run lint --stream",
2727
"add-contributor": "all-contributors add",
2828
"generate": "all-contributors generate",
2929
"postinstall": "rimraf node_modules/@types/react-native && rimraf packages/app/node_modules/styled-components node_modules/react-split-pane/node_modules/react* && yarn lerna run install-dependencies --scope vscode-textmate --scope codesandbox-browserfs --scope sse-loading-screen --stream && opencollective postinstall",
@@ -42,11 +42,15 @@
4242
"packages/sse-hooks",
4343
"packages/react-embed",
4444
"packages/dynamic-pages",
45-
"packages/notifications"
45+
"packages/notifications",
46+
"packages/deps"
4647
],
4748
"nohoist": [
4849
"**/react-codemirror2",
49-
"**/react-codemirror2/**"
50+
"**/react-codemirror2/**",
51+
"app/webpack",
52+
"app/acorn-dynamic-import",
53+
"codesandbox-deps/tern"
5054
]
5155
},
5256
"resolutions": {

Diff for: packages/app/config/build.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const isDev = process.env.NODE_ENV === 'development';
2+
const staticAssets = [
3+
{
4+
from: 'standalone-packages/vscode-editor/release/min/vs',
5+
to: 'public/vscode22/vs',
6+
},
7+
{
8+
from: 'standalone-packages/vscode-extensions/out',
9+
to: 'public/vscode-extensions/v8',
10+
},
11+
{
12+
from: 'node_modules/onigasm/lib/onigasm.wasm',
13+
to: 'public/onigasm/2.2.1/onigasm.wasm',
14+
},
15+
{
16+
from:
17+
'standalone-packages/vscode-textmate/node_modules/onigasm/lib/onigasm.wasm',
18+
to: 'public/onigasm/2.1.0/onigasm.wasm',
19+
},
20+
{
21+
from: 'node_modules/monaco-vue/release/min',
22+
to: 'public/14/vs/language/vue',
23+
},
24+
{
25+
from: 'standalone-packages/monaco-editor/release/min/vs',
26+
to: 'public/14/vs',
27+
},
28+
{
29+
from: 'packages/app/static',
30+
to: 'static',
31+
},
32+
{
33+
from: isDev
34+
? 'standalone-packages/codesandbox-browserfs/build'
35+
: 'standalone-packages/codesandbox-browserfs/dist',
36+
to: 'static/browserfs3',
37+
},
38+
];
39+
40+
module.exports = {
41+
staticAssets,
42+
};

Diff for: packages/app/config/webpack.common.js

+23-77
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ const fs = require('fs');
44
const paths = require('./paths');
55
const HtmlWebpackPlugin = require('html-webpack-plugin');
66
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
7-
const CopyWebpackPlugin = require('copy-webpack-plugin');
8-
const HappyPack = require('happypack');
7+
const threadLoader = require('thread-loader');
98
const WatchMissingNodeModulesPlugin = require('../scripts/utils/WatchMissingNodeModulesPlugin');
109
const env = require('@codesandbox/common/lib/config/env');
1110
const getHost = require('@codesandbox/common/lib/utils/host');
@@ -19,20 +18,8 @@ const __DEV__ = NODE_ENV === 'development'; // eslint-disable-line no-underscore
1918
const __PROD__ = NODE_ENV === 'production'; // eslint-disable-line no-underscore-dangle
2019
// const __TEST__ = NODE_ENV === 'test'; // eslint-disable-line no-underscore-dangle
2120
const babelConfig = __DEV__ && !SANDBOX_ONLY ? babelDev : babelProd;
22-
2321
const publicPath = SANDBOX_ONLY || __DEV__ ? '/' : getHost.default() + '/';
24-
25-
let threads = 1;
26-
27-
try {
28-
if (process.env.CIRCLECI) {
29-
threads = 2;
30-
} else {
31-
threads = Math.max(1, require('os').cpus().length - 1);
32-
}
33-
} catch (e) {
34-
threads = 3;
35-
}
22+
const isLint = 'LINT' in process.env;
3623

3724
// Shim for `eslint-plugin-vue/lib/index.js`
3825
const ESLINT_PLUGIN_VUE_INDEX = `module.exports = {
@@ -63,6 +50,14 @@ const ESLINT_PLUGIN_VUE_INDEX = `module.exports = {
6350

6451
const sepRe = `\\${path.sep}`; // path separator regex
6552

53+
const threadPoolConfig = {
54+
workers: 2,
55+
};
56+
57+
if (!isLint) {
58+
threadLoader.warmup(threadPoolConfig, ['babel-loader']);
59+
}
60+
6661
module.exports = {
6762
entry: SANDBOX_ONLY
6863
? {
@@ -101,6 +96,7 @@ module.exports = {
10196
publicPath,
10297
globalObject: 'this',
10398
jsonpFunction: 'csbJsonP', // So we don't conflict with webpack generated libraries in the sandbox
99+
pathinfo: false,
104100
},
105101

106102
module: {
@@ -172,13 +168,18 @@ module.exports = {
172168
/typescriptServices\.js$/,
173169
/\.no-webpack\./,
174170
],
175-
loader: 'happypack/loader',
176-
},
177-
178-
{
179-
test: /\.tsx?$/,
180-
exclude: [/node_modules/],
181-
loader: 'happypack/loader',
171+
use: [
172+
!isLint
173+
? {
174+
loader: 'thread-loader',
175+
options: threadPoolConfig,
176+
}
177+
: false,
178+
{
179+
loader: 'babel-loader',
180+
options: babelConfig,
181+
},
182+
].filter(Boolean),
182183
},
183184

184185
// `eslint-plugin-vue/lib/index.js` depends on `fs` module we cannot use in browsers, so needs shimming.
@@ -333,15 +334,6 @@ module.exports = {
333334
},
334335

335336
plugins: [
336-
new HappyPack({
337-
loaders: [
338-
{
339-
path: 'babel-loader',
340-
query: babelConfig,
341-
},
342-
],
343-
threads,
344-
}),
345337
...(SANDBOX_ONLY
346338
? [
347339
new HtmlWebpackPlugin({
@@ -462,51 +454,5 @@ module.exports = {
462454
// makes the discovery automatic so you don't have to restart.
463455
// See https://github.com/facebookincubator/create-react-app/issues/186
464456
new WatchMissingNodeModulesPlugin(paths.appNodeModules),
465-
// Make the monaco editor work
466-
new CopyWebpackPlugin(
467-
[
468-
{
469-
from: '../../standalone-packages/vscode-editor/release/min/vs',
470-
to: 'public/vscode22/vs',
471-
force: true,
472-
},
473-
{
474-
from: '../../standalone-packages/vscode-extensions/out',
475-
to: 'public/vscode-extensions/v8',
476-
force: true,
477-
},
478-
{
479-
from: '../../node_modules/onigasm/lib/onigasm.wasm',
480-
to: 'public/onigasm/2.2.1/onigasm.wasm',
481-
},
482-
{
483-
from:
484-
'../../standalone-packages/vscode-textmate/node_modules/onigasm/lib/onigasm.wasm',
485-
to: 'public/onigasm/2.1.0/onigasm.wasm',
486-
},
487-
{
488-
from: '../../node_modules/monaco-vue/release/min',
489-
to: 'public/14/vs/language/vue',
490-
},
491-
{
492-
from: '../../standalone-packages/monaco-editor/release/min/vs',
493-
to: 'public/14/vs',
494-
},
495-
{
496-
from: '../sse-hooks/dist',
497-
to: 'public/sse-hooks',
498-
},
499-
{
500-
from: 'static',
501-
to: 'static',
502-
},
503-
{
504-
from: __DEV__
505-
? '../../standalone-packages/codesandbox-browserfs/build'
506-
: '../../standalone-packages/codesandbox-browserfs/dist',
507-
to: 'static/browserfs3',
508-
},
509-
].filter(x => x)
510-
),
511457
].filter(Boolean),
512458
};

0 commit comments

Comments
 (0)