diff --git a/package.json b/package.json index f13a413c5cc..4a1ae575e3a 100644 --- a/package.json +++ b/package.json @@ -126,7 +126,7 @@ "rimraf": "^3.0.2", "ts-jest": "^25.3.0", "typescript": "^3.9.5", - "webpack": "^4.42.0", + "webpack": "^4.43.0", "yeoman-test": "^2.3.0" } } diff --git a/packages/utils/package.json b/packages/utils/package.json index 508d16f6fbe..68f9d693e52 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -20,6 +20,9 @@ "yeoman-environment": "2.8.1", "yeoman-generator": "4.7.2" }, + "peerDependencies": { + "webpack": "4.x.x || 5.x.x" + }, "devDependencies": { "@types/got": "9.6.9", "@types/prettier": "1.19.0", diff --git a/packages/utils/src/isWebpack5.ts b/packages/utils/src/isWebpack5.ts new file mode 100644 index 00000000000..54a92f32543 --- /dev/null +++ b/packages/utils/src/isWebpack5.ts @@ -0,0 +1,3 @@ +import { version } from 'webpack'; + +export const isWebpack5 = (): boolean => version.startsWith('5'); diff --git a/packages/utils/src/prop-types.ts b/packages/utils/src/prop-types.ts index 06973147222..ac0a8005f25 100644 --- a/packages/utils/src/prop-types.ts +++ b/packages/utils/src/prop-types.ts @@ -1,38 +1,47 @@ +import { isWebpack5 } from './isWebpack5'; +import { config } from 'webpack'; + +let configKeys; +if (isWebpack5()) { + configKeys = Object.keys(config.getNormalizedWebpackOptions({})); +} else { + configKeys = [ + 'amd', + 'bail', + 'cache', + 'context', + 'devServer', + 'devtool', + 'entry', + 'externals', + 'merge', + 'mode', + 'module', + 'node', + 'optimization', + 'output', + 'parallelism', + 'performance', + 'plugins', + 'profile', + 'recordsInputPath', + 'recordsOutputPath', + 'recordsPath', + 'resolve', + 'resolveLoader', + 'splitChunks', + 'stats', + 'target', + 'topScope', + 'watch', + 'watchOptions', + ]; +} + /** * * A Set of all accepted properties * * @returns {Set} A new set with accepted webpack properties */ - -export const PROP_TYPES: Set = new Set([ - 'amd', - 'bail', - 'cache', - 'context', - 'devServer', - 'devtool', - 'entry', - 'externals', - 'merge', - 'mode', - 'module', - 'node', - 'optimization', - 'output', - 'parallelism', - 'performance', - 'plugins', - 'profile', - 'recordsInputPath', - 'recordsOutputPath', - 'recordsPath', - 'resolve', - 'resolveLoader', - 'splitChunks', - 'stats', - 'target', - 'topScope', - 'watch', - 'watchOptions', -]); +export const PROP_TYPES: Set = new Set(configKeys); diff --git a/yarn.lock b/yarn.lock index 0c8a1f39bf4..5e4bd2d4c4a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11959,7 +11959,7 @@ webpack-sources@^1.4.0, webpack-sources@^1.4.1: source-list-map "^2.0.0" source-map "~0.6.1" -webpack@4.x.x, webpack@^4.42.0: +webpack@4.x.x, webpack@^4.43.0: version "4.43.0" resolved "https://registry.yarnpkg.com/webpack/-/webpack-4.43.0.tgz#c48547b11d563224c561dad1172c8aa0b8a678e6" integrity sha512-GW1LjnPipFW2Y78OOab8NJlCflB7EFskMih2AHdvjbpKMeDJqEgSx24cXXXiPS65+WSwVyxtDsJH6jGX2czy+g==