-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Build improvements #2076
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
Build improvements #2076
Changes from 15 commits
79916c2
057d47a
27145ec
d0b7869
fd8d12e
5ef8a8a
b9de1f9
f309784
58e420f
0d5ef6b
39fcae1
31b3c20
51ee807
a6877b2
e7db9e6
25d4839
e142676
2ab9b69
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| const isDev = process.env.NODE_ENV === 'development'; | ||
| const staticAssets = [ | ||
| { | ||
| from: 'standalone-packages/vscode-editor/release/min/vs', | ||
| to: 'public/vscode22/vs', | ||
| }, | ||
| { | ||
| from: 'standalone-packages/vscode-extensions/out', | ||
| to: 'public/vscode-extensions/v8', | ||
| }, | ||
| { | ||
| from: 'node_modules/onigasm/lib/onigasm.wasm', | ||
| to: 'public/onigasm/2.2.1/onigasm.wasm', | ||
| }, | ||
| { | ||
| from: | ||
| 'standalone-packages/vscode-textmate/node_modules/onigasm/lib/onigasm.wasm', | ||
| to: 'public/onigasm/2.1.0/onigasm.wasm', | ||
| }, | ||
| { | ||
| from: 'node_modules/monaco-vue/release/min', | ||
| to: 'public/14/vs/language/vue', | ||
| }, | ||
| { | ||
| from: 'standalone-packages/monaco-editor/release/min/vs', | ||
| to: 'public/14/vs', | ||
| }, | ||
| { | ||
| from: 'packages/app/static', | ||
| to: 'static', | ||
| }, | ||
| { | ||
| from: isDev | ||
| ? 'standalone-packages/codesandbox-browserfs/build' | ||
| : 'standalone-packages/codesandbox-browserfs/dist', | ||
| to: 'static/browserfs3', | ||
| }, | ||
| ]; | ||
|
|
||
| module.exports = { | ||
| staticAssets, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,8 +4,7 @@ const fs = require('fs'); | |
| const paths = require('./paths'); | ||
| const HtmlWebpackPlugin = require('html-webpack-plugin'); | ||
| const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin'); | ||
| const CopyWebpackPlugin = require('copy-webpack-plugin'); | ||
| const HappyPack = require('happypack'); | ||
| const threadLoader = require('thread-loader'); | ||
| const WatchMissingNodeModulesPlugin = require('../scripts/utils/WatchMissingNodeModulesPlugin'); | ||
| const env = require('@codesandbox/common/lib/config/env'); | ||
| const getHost = require('@codesandbox/common/lib/utils/host'); | ||
|
|
@@ -19,20 +18,8 @@ const __DEV__ = NODE_ENV === 'development'; // eslint-disable-line no-underscore | |
| const __PROD__ = NODE_ENV === 'production'; // eslint-disable-line no-underscore-dangle | ||
| // const __TEST__ = NODE_ENV === 'test'; // eslint-disable-line no-underscore-dangle | ||
| const babelConfig = __DEV__ && !SANDBOX_ONLY ? babelDev : babelProd; | ||
|
|
||
| const publicPath = SANDBOX_ONLY || __DEV__ ? '/' : getHost.default() + '/'; | ||
|
|
||
| let threads = 1; | ||
|
|
||
| try { | ||
| if (process.env.CIRCLECI) { | ||
| threads = 2; | ||
| } else { | ||
| threads = Math.max(1, require('os').cpus().length - 1); | ||
| } | ||
| } catch (e) { | ||
| threads = 3; | ||
| } | ||
| const isLint = 'LINT' in process.env; | ||
|
|
||
| // Shim for `eslint-plugin-vue/lib/index.js` | ||
| const ESLINT_PLUGIN_VUE_INDEX = `module.exports = { | ||
|
|
@@ -63,6 +50,14 @@ const ESLINT_PLUGIN_VUE_INDEX = `module.exports = { | |
|
|
||
| const sepRe = `\\${path.sep}`; // path separator regex | ||
|
|
||
| const threadPoolConfig = { | ||
| workers: 2, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did this make it faster than
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't see any obvious improvements, even when using
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't see improvements either, let's keep it at 2. |
||
| }; | ||
|
|
||
| if (!isLint) { | ||
| threadLoader.warmup(threadPoolConfig, ['babel-loader']); | ||
| } | ||
|
|
||
| module.exports = { | ||
| entry: SANDBOX_ONLY | ||
| ? { | ||
|
|
@@ -101,6 +96,7 @@ module.exports = { | |
| publicPath, | ||
| globalObject: 'this', | ||
| jsonpFunction: 'csbJsonP', // So we don't conflict with webpack generated libraries in the sandbox | ||
| pathinfo: false, | ||
| }, | ||
|
|
||
| module: { | ||
|
|
@@ -172,13 +168,18 @@ module.exports = { | |
| /typescriptServices\.js$/, | ||
| /\.no-webpack\./, | ||
| ], | ||
| loader: 'happypack/loader', | ||
| }, | ||
|
|
||
| { | ||
| test: /\.tsx?$/, | ||
| exclude: [/node_modules/], | ||
| loader: 'happypack/loader', | ||
| use: [ | ||
| !isLint | ||
| ? { | ||
| loader: 'thread-loader', | ||
| options: threadPoolConfig, | ||
| } | ||
| : false, | ||
| { | ||
| loader: 'babel-loader', | ||
| options: babelConfig, | ||
| }, | ||
| ].filter(Boolean), | ||
| }, | ||
|
|
||
| // `eslint-plugin-vue/lib/index.js` depends on `fs` module we cannot use in browsers, so needs shimming. | ||
|
|
@@ -333,15 +334,6 @@ module.exports = { | |
| }, | ||
|
|
||
| plugins: [ | ||
| new HappyPack({ | ||
| loaders: [ | ||
| { | ||
| path: 'babel-loader', | ||
| query: babelConfig, | ||
| }, | ||
| ], | ||
| threads, | ||
| }), | ||
| ...(SANDBOX_ONLY | ||
| ? [ | ||
| new HtmlWebpackPlugin({ | ||
|
|
@@ -462,51 +454,5 @@ module.exports = { | |
| // makes the discovery automatic so you don't have to restart. | ||
| // See https://github.com/facebookincubator/create-react-app/issues/186 | ||
| new WatchMissingNodeModulesPlugin(paths.appNodeModules), | ||
| // Make the monaco editor work | ||
| new CopyWebpackPlugin( | ||
| [ | ||
| { | ||
| from: '../../standalone-packages/vscode-editor/release/min/vs', | ||
| to: 'public/vscode22/vs', | ||
| force: true, | ||
| }, | ||
| { | ||
| from: '../../standalone-packages/vscode-extensions/out', | ||
| to: 'public/vscode-extensions/v8', | ||
| force: true, | ||
| }, | ||
| { | ||
| from: '../../node_modules/onigasm/lib/onigasm.wasm', | ||
| to: 'public/onigasm/2.2.1/onigasm.wasm', | ||
| }, | ||
| { | ||
| from: | ||
| '../../standalone-packages/vscode-textmate/node_modules/onigasm/lib/onigasm.wasm', | ||
| to: 'public/onigasm/2.1.0/onigasm.wasm', | ||
| }, | ||
| { | ||
| from: '../../node_modules/monaco-vue/release/min', | ||
| to: 'public/14/vs/language/vue', | ||
| }, | ||
| { | ||
| from: '../../standalone-packages/monaco-editor/release/min/vs', | ||
| to: 'public/14/vs', | ||
| }, | ||
| { | ||
| from: '../sse-hooks/dist', | ||
| to: 'public/sse-hooks', | ||
| }, | ||
| { | ||
| from: 'static', | ||
| to: 'static', | ||
| }, | ||
| { | ||
| from: __DEV__ | ||
| ? '../../standalone-packages/codesandbox-browserfs/build' | ||
| : '../../standalone-packages/codesandbox-browserfs/dist', | ||
| to: 'static/browserfs3', | ||
| }, | ||
| ].filter(x => x) | ||
| ), | ||
| ].filter(Boolean), | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Hacky?) Fix for webpack/webpack#8656 until acornjs/acorn#834 gets merged.