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
fix(web): fix styles vendorChunk in webpack 5 #6822
Changes from 3 commits
1a5b78b
283fcc2
eaa6394
3b129c9
10a3901
e08b534
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 |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
// TODO: import from 'webpack' in Nx 13 | ||
import type { Module, ModuleGraph, ChunkGraph, Chunk } from 'webpack-5'; | ||
import { LicenseWebpackPlugin } from 'license-webpack-plugin'; | ||
import { WebpackConfigOptions, BuildOptions } from '../build-options'; | ||
import { | ||
|
@@ -120,30 +122,32 @@ export function getBrowserConfig(wco: WebpackConfigOptions) { | |
} | ||
: {}), | ||
vendors: false, | ||
// TODO(jack): Support both 4 and 5 | ||
vendor: !!buildOptions.vendorChunk && { | ||
name: 'vendor', | ||
chunks: isWebpack5 ? (chunk) => chunk.name === 'main' : 'initial', | ||
enforce: true, | ||
test: isWebpack5 | ||
? /[\\/]node_modules[\\/]/ | ||
: ( | ||
module: { nameForCondition?: Function }, | ||
chunks: Array<{ name: string }> | ||
) => { | ||
const moduleName = module.nameForCondition | ||
? module.nameForCondition() | ||
: ''; | ||
test: ( | ||
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. The |
||
module: Module, | ||
// `CacheGroupsContext`, but it's not exported from webpack types | ||
context: { moduleGraph: ModuleGraph; chunkGraph: ChunkGraph } | ||
) => { | ||
const moduleName = module.nameForCondition | ||
? module.nameForCondition() | ||
: ''; | ||
// TODO(jack): Remove in Nx 13 | ||
const chunks = isWebpack5 | ||
? context.chunkGraph.getModuleChunks(module) | ||
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 was going for the same condition as the webpack 4. |
||
: (context as unknown as Chunk[]); | ||
|
||
return ( | ||
/[\\/]node_modules[\\/]/.test(moduleName) && | ||
!chunks.some( | ||
({ name }) => | ||
isPolyfillsEntry(name) || | ||
globalStylesBundleNames.includes(name) | ||
) | ||
); | ||
}, | ||
return ( | ||
/[\\/]node_modules[\\/]/.test(moduleName) && | ||
!chunks.some( | ||
({ name }) => | ||
isPolyfillsEntry(name) || | ||
globalStylesBundleNames.includes(name) | ||
) | ||
); | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
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.
I did not want to introduce problems by changing to
webpack@5
, so I am adding this alias asThere 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.
I think this would cause a problem if the user does not want webpack 5 installed. For now I think it's better to leave things untyped until Nx 13 when we remove webpack 4.
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.
@jaysoo it's just a type for now (
@types/webpack
), would that be a problem too?I have pushed 3b129c9 to remove the dependency and changed to stub types. This should make it easier to swtich the types for Nx 13.