-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
feat: Improve webpack-dev-server performance #15158
Changes from all commits
f636021
b9405f6
b104c85
3852a38
442fc14
421b53e
b721f05
73baeeb
fe2a5ae
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 |
---|---|---|
@@ -1,28 +1,51 @@ | ||
import { debug as debugFn } from 'debug' | ||
import * as path from 'path' | ||
import { Configuration } from 'webpack' | ||
import * as webpack from 'webpack' | ||
import { merge } from 'webpack-merge' | ||
import defaultWebpackConfig from './webpack.config' | ||
import LazyCompilePlugin from 'lazy-compile-webpack-plugin' | ||
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. This is the one: https://github.com/liximomo/lazy-compile-webpack-plugin ? I'm surprised more people are not using this 🤔 seems not well known |
||
import CypressCTOptionsPlugin, { CypressCTOptionsPluginOptions } from './plugin' | ||
|
||
const debug = debugFn('cypress:webpack-dev-server:makeWebpackConfig') | ||
const WEBPACK_MAJOR_VERSION = Number(webpack.version.split('.')[0]) | ||
|
||
export interface UserWebpackDevServerOptions { | ||
/** | ||
* if `true` will compile all the specs together when the first one is request and can slow up initial build time. | ||
* @default false | ||
*/ | ||
disableLazyCompilation?: boolean | ||
} | ||
|
||
interface MakeWebpackConfigOptions extends CypressCTOptionsPluginOptions, UserWebpackDevServerOptions { | ||
webpackDevServerPublicPathRoute: string | ||
isOpenMode: boolean | ||
} | ||
|
||
const mergePublicPath = (baseValue, userValue = '/') => { | ||
return path.join(baseValue, userValue, '/') | ||
} | ||
|
||
interface MakeWebpackConfigOptions extends CypressCTOptionsPluginOptions { | ||
webpackDevServerPublicPathRoute: string | ||
function getLazyCompilationWebpackConfig (options: MakeWebpackConfigOptions): webpack.Configuration { | ||
if (options.disableLazyCompilation || !options.isOpenMode) { | ||
return {} | ||
} | ||
|
||
switch (WEBPACK_MAJOR_VERSION) { | ||
case 4: | ||
return { plugins: [new LazyCompilePlugin()] } | ||
case 5: | ||
return { experiments: { lazyCompilation: true } } as webpack.Configuration | ||
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. Right - so webpack 5 has lazy built in, but webpack 4 you need the plugin? 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 think this should be clear from the code <3
|
||
default: | ||
return { } | ||
} | ||
} | ||
|
||
export async function makeWebpackConfig (userWebpackConfig: Configuration, options: MakeWebpackConfigOptions): Promise<Configuration> { | ||
export async function makeWebpackConfig (userWebpackConfig: webpack.Configuration, options: MakeWebpackConfigOptions): Promise<webpack.Configuration> { | ||
const { projectRoot, webpackDevServerPublicPathRoute, files, supportFile, devServerEvents } = options | ||
|
||
debug(`User passed in webpack config with values %o`, userWebpackConfig) | ||
|
||
const defaultWebpackConfig = require('./webpack.config') | ||
|
||
debug(`Merging Evergreen's webpack config with users'`) | ||
|
||
debug(`New webpack entries %o`, files) | ||
debug(`Project root`, projectRoot) | ||
debug(`Support file`, supportFile) | ||
|
@@ -45,7 +68,12 @@ export async function makeWebpackConfig (userWebpackConfig: Configuration, optio | |
], | ||
} | ||
|
||
const mergedConfig = merge<Configuration>(userWebpackConfig, defaultWebpackConfig, dynamicWebpackConfig) | ||
const mergedConfig = merge<webpack.Configuration>( | ||
userWebpackConfig, | ||
defaultWebpackConfig, | ||
dynamicWebpackConfig, | ||
getLazyCompilationWebpackConfig(options), | ||
) | ||
|
||
mergedConfig.entry = entry | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13421,7 +13421,7 @@ detect-node@^2.0.4: | |
resolved "https://registry.yarnpkg.com/detect-node/-/detect-node-2.0.4.tgz#014ee8f8f669c5c58023da64b8179c083a28c46c" | ||
integrity sha512-ZIzRpLJrOj7jjP2miAtgqIfmzbxa4ZOr5jJc601zklsfEx9oTzmmj2nVpIPRpNlRTIh8lc1kyViIY7BWSGNmKw== | ||
|
||
[email protected]: | ||
[email protected], detect-port-alt@^1.1.6: | ||
version "1.1.6" | ||
resolved "https://registry.yarnpkg.com/detect-port-alt/-/detect-port-alt-1.1.6.tgz#24707deabe932d4a3cf621302027c2b266568275" | ||
integrity sha512-5tQykt+LqfJFBEYaDITx7S7cR7mJ/zQmLXZ2qt5w04ainYZw6tBf9dBunMjVeVOdYVRUzUOE4HkY5J7+uttb5Q== | ||
|
@@ -21463,6 +21463,14 @@ lazy-cache@^1.0.3: | |
resolved "https://registry.yarnpkg.com/lazy-cache/-/lazy-cache-1.0.4.tgz#a1d78fc3a50474cb80845d3b3b6e1da49a446e8e" | ||
integrity sha1-odePw6UEdMuAhF07O24dpJpEbo4= | ||
|
||
[email protected]: | ||
version "0.1.11" | ||
resolved "https://registry.yarnpkg.com/lazy-compile-webpack-plugin/-/lazy-compile-webpack-plugin-0.1.11.tgz#be3b9487ccc731a606dc55bcfcd80000c72e4237" | ||
integrity sha512-d2D72x0XqFSj83SRmgx1dvgRvmyIoXpC2lMj+XVS+xzt0FxXDPzF/2FbxOVmW9gzp6d8U29Ne4RGF4x+MTYwow== | ||
dependencies: | ||
detect-port-alt "^1.1.6" | ||
loader-utils "^1.2.3" | ||
|
||
lazy-property@~1.0.0: | ||
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/lazy-property/-/lazy-property-1.0.0.tgz#84ddc4b370679ba8bd4cdcfa4c06b43d57111147" | ||
|
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.
What is this? Is this just to speed up CI?
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.
And show users how to optimize theirs.