@workleap/webpack-configs 1.6.0 → 1.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @workleap/webpack-configs
|
|
2
2
|
|
|
3
|
+
## 1.6.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#302](https://github.com/workleap/wl-web-configs/pull/302) [`a0c552f`](https://github.com/workleap/wl-web-configs/commit/a0c552fb26428fe854077351b78fe6dbe393b140) Thanks [@alexasselin008](https://github.com/alexasselin008)! - Bump release to test OIDC deployment
|
|
8
|
+
|
|
9
|
+
## 1.6.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#300](https://github.com/workleap/wl-web-configs/pull/300) [`95ba69a`](https://github.com/workleap/wl-web-configs/commit/95ba69af8f342cfd5a69c4dd067b851f7a4817c3) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Fixing deployment of previous version.
|
|
14
|
+
|
|
15
|
+
## 1.6.1
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- [#298](https://github.com/workleap/wl-web-configs/pull/298) [`ec6e2bb`](https://github.com/workleap/wl-web-configs/commit/ec6e2bba95dcedad667afae6ba99ed7d6ce27a6c) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Updated dependencies.
|
|
20
|
+
|
|
3
21
|
## 1.6.0
|
|
4
22
|
|
|
5
23
|
### Minor Changes
|
|
@@ -5,7 +5,7 @@ import node_path from "node:path";
|
|
|
5
5
|
;// CONCATENATED MODULE: ./src/transformers/moduleRules.ts
|
|
6
6
|
|
|
7
7
|
function isNameMatchingLoader(loader, name) {
|
|
8
|
-
return loader === name || loader.
|
|
8
|
+
return loader === name || loader.includes(`${node_path.sep}${name}${node_path.sep}`) || loader.includes(`@${name}${node_path.sep}`);
|
|
9
9
|
}
|
|
10
10
|
function matchLoaderName(name) {
|
|
11
11
|
const matcher = (moduleRule)=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformers/moduleRules.js","sources":["webpack://@workleap/webpack-configs/./src/transformers/moduleRules.ts"],"sourcesContent":["import path from \"node:path\";\nimport type { RuleSetRule, RuleSetUseItem } from \"webpack\";\nimport type { WebpackConfig } from \"../types.ts\";\n\nexport type ModuleRuleMatcher = (moduleRule: RuleSetRule | RuleSetUseItem, index: number, array: RuleSetRule[] | RuleSetUseItem[]) => boolean;\n\nexport type WithModuleRuleMatcherInfo = {\n info: {\n type: string;\n value: string;\n };\n} & ModuleRuleMatcher;\n\nfunction isNameMatchingLoader(loader: string, name: string) {\n return loader === name || loader.indexOf(`${path.sep}${name}${path.sep}`) !== -1 || loader.indexOf(`@${name}${path.sep}`) !== -1;\n}\n\nexport function matchLoaderName(name: string): ModuleRuleMatcher {\n const matcher: WithModuleRuleMatcherInfo = moduleRule => {\n if (typeof moduleRule === \"string\") {\n return isNameMatchingLoader(moduleRule, name);\n } else {\n if (\"loader\" in moduleRule && moduleRule.loader) {\n return isNameMatchingLoader(moduleRule.loader, name);\n }\n }\n\n return false;\n };\n\n // Add contextual information about the matcher for debugging.\n matcher.info = {\n type: matchLoaderName.name,\n value: name\n };\n\n return matcher;\n}\n\nexport type AssetModuleType =\n | \"javascript/auto\"\n | \"javascript/dynamic\"\n | \"javascript/esm\"\n | \"json\"\n | \"webassembly/sync\"\n | \"webassembly/async\"\n | \"asset\"\n | \"asset/source\"\n | \"asset/resource\"\n | \"asset/inline\";\n\nexport function matchAssetModuleType(type: AssetModuleType): ModuleRuleMatcher {\n const matcher: WithModuleRuleMatcherInfo = moduleRule => {\n if (typeof moduleRule !== \"string\" && \"type\" in moduleRule) {\n return moduleRule.type === type;\n }\n\n return false;\n };\n\n // Add contextual information about the matcher for debugging.\n matcher.info = {\n type: matchAssetModuleType.name,\n value: type\n };\n\n return matcher;\n}\n\nexport function matchTest(test: string | RegExp): ModuleRuleMatcher {\n const matcher: WithModuleRuleMatcherInfo = moduleRule => {\n if (typeof moduleRule !== \"string\" && \"test\" in moduleRule) {\n if (typeof moduleRule.test === \"object\" && typeof test === \"object\") {\n // Assuming it's regular expressions.\n return moduleRule.test.toString() === test.toString();\n }\n\n return moduleRule.test === test;\n }\n\n return false;\n };\n\n // Add contextual information about the matcher for debugging.\n matcher.info = {\n type: matchTest.name,\n value: test.toString()\n };\n\n return matcher;\n}\n\nexport interface ModuleRuleMatch {\n moduleRule: RuleSetRule | RuleSetUseItem;\n index: number;\n parent: RuleSetRule[] | RuleSetUseItem[];\n}\n\nfunction toMatch(moduleRule: RuleSetRule | RuleSetUseItem, index: number, parent: RuleSetRule[] | RuleSetUseItem[]) {\n return {\n moduleRule,\n index,\n parent\n };\n}\n\nfunction isRuleSetRule(value: RuleSetRule | RuleSetUseItem): value is RuleSetRule {\n return (value as RuleSetRule).use !== undefined || (value as RuleSetRule).oneOf !== undefined;\n}\n\nfunction findModuleRulesRecursively(moduleRules: RuleSetRule[] | RuleSetUseItem[], matcher: ModuleRuleMatcher, parent: RuleSetRule[] | RuleSetUseItem[], matches: ModuleRuleMatch[]) {\n moduleRules.forEach((x, index, array) => {\n if (x) {\n if (matcher(x, index, array)) {\n matches.push(toMatch(x, index, parent));\n } else {\n if (isRuleSetRule(x)) {\n if (x.use) {\n findModuleRulesRecursively(x.use as RuleSetUseItem[], matcher, x.use as RuleSetUseItem[], matches);\n } else if (x.oneOf) {\n // This error seems to have been introduced by either TS 5.2. or webpack 5.88.1 (https://github.com/webpack/webpack/releases/tag/v5.88.1),\n // I am not sure what changed thought.\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n findModuleRulesRecursively(x.oneOf, matcher, x.oneOf, matches);\n }\n }\n }\n }\n });\n}\n\nexport function findModuleRule(config: WebpackConfig, matcher: ModuleRuleMatcher) {\n const moduleRules = config.module?.rules;\n\n if (!moduleRules) {\n return;\n }\n\n const matches: ModuleRuleMatch[] = [];\n\n findModuleRulesRecursively(moduleRules as RuleSetRule[], matcher, moduleRules as RuleSetRule[], matches);\n\n if (matches.length > 1) {\n const matcherInfo = (matcher as WithModuleRuleMatcherInfo).info;\n\n throw new Error(`[webpack-configs] Found more than 1 matching module rule.\\n[webpack-configs] Matcher: \"${JSON.stringify(matcherInfo)}\"\\n[webpack-configs] Matches: \"${JSON.stringify(matches.map(x => x.moduleRule))}\"`);\n }\n\n return matches[0];\n}\n\nexport function findModuleRules(config: WebpackConfig, matcher: ModuleRuleMatcher) {\n const moduleRules = config.module?.rules;\n\n if (!moduleRules) {\n return;\n }\n\n const matches: ModuleRuleMatch[] = [];\n\n findModuleRulesRecursively(moduleRules as RuleSetRule[], matcher, moduleRules as RuleSetRule[], matches);\n\n return matches;\n}\n\nexport function addBeforeModuleRule(config: WebpackConfig, matcher: ModuleRuleMatcher, newModuleRules: RuleSetRule[] | RuleSetUseItem[]) {\n const match = findModuleRule(config, matcher);\n\n if (match) {\n match.parent.splice(match.index, 0, ...newModuleRules);\n } else {\n const matcherInfo = (matcher as WithModuleRuleMatcherInfo).info;\n\n throw new Error(`[webpack-configs] Couldn't add the new module rules because no match has been found.\\n[webpack-configs] Matcher: \"${JSON.stringify(matcherInfo)}\"`);\n }\n}\n\nexport function addAfterModuleRule(config: WebpackConfig, matcher: ModuleRuleMatcher, newModuleRules: RuleSetRule[] | RuleSetUseItem[]) {\n const match = findModuleRule(config, matcher);\n\n if (match) {\n match.parent.splice(match.index + 1, 0, ...newModuleRules);\n } else {\n const matcherInfo = (matcher as WithModuleRuleMatcherInfo).info;\n\n throw new Error(`[webpack-configs] Couldn't add the new module rules because no match has been found.\\n[webpack-configs] Matcher: \"${JSON.stringify(matcherInfo)}\"`);\n }\n}\n\nexport function replaceModuleRule(config: WebpackConfig, matcher: ModuleRuleMatcher, newModuleRule: RuleSetRule | RuleSetUseItem) {\n const match = findModuleRule(config, matcher);\n\n if (match) {\n match.parent[match.index] = newModuleRule;\n } else {\n const matcherInfo = (matcher as WithModuleRuleMatcherInfo).info;\n\n throw new Error(`[webpack-configs] Couldn't replace the module rule because no match has been found.\\n[webpack-configs] Matcher: \"${JSON.stringify(matcherInfo)}\"`);\n }\n}\n\nexport function removeModuleRules(config: WebpackConfig, matcher: ModuleRuleMatcher) {\n const moduleRules = config.module?.rules;\n\n if (!moduleRules) {\n return;\n }\n\n const matches: ModuleRuleMatch[] = [];\n\n findModuleRulesRecursively(moduleRules as RuleSetRule[], matcher, moduleRules as RuleSetRule[], matches);\n\n if (matches.length > 0) {\n // Must keep the initial parent arrays' length to calculate the adjustment\n // once the first match has been deleted.\n const initialParentLengths = new Map<RuleSetRule[] | RuleSetUseItem[], number>(matches.map(x => [x.parent, x.parent.length]));\n\n matches.forEach(x => {\n const positionAdjustment = initialParentLengths.get(x.parent)! - x.parent.length;\n\n x.parent.splice(x.index - positionAdjustment, 1);\n });\n } else {\n const matcherInfo = (matcher as WithModuleRuleMatcherInfo).info;\n\n throw new Error(`[webpack-configs] Didn't remove any module rules because no match has been found.\\n[webpack-configs] Matcher: \"${matcherInfo}\"`);\n }\n}\n"],"names":["path","isNameMatchingLoader","loader","name","matchLoaderName","matcher","moduleRule","matchAssetModuleType","type","matchTest","test","toMatch","index","parent","isRuleSetRule","value","undefined","findModuleRulesRecursively","moduleRules","matches","x","array","findModuleRule","config","matcherInfo","Error","JSON","findModuleRules","addBeforeModuleRule","newModuleRules","match","addAfterModuleRule","replaceModuleRule","newModuleRule","removeModuleRules","initialParentLengths","Map","positionAdjustment"],"mappings":";;;;;AAA6B;AAa7B,SAASC,qBAAqBC,MAAc,EAAEC,IAAY;IACtD,OAAOD,WAAWC,QAAQD,OAAO,OAAO,CAAC,GAAGF,aAAQ,GAAGG,OAAOH,aAAQ,EAAE,MAAM,CAAC,KAAKE,OAAO,OAAO,CAAC,CAAC,CAAC,EAAEC,OAAOH,aAAQ,EAAE,MAAM,CAAC;AACnI;AAEO,SAASI,gBAA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C,IAA8CjB,QAAQ,GAAG,CAACC,CAAAA,IAAK;gBAACA,EAAE,MAAM;gBAAEA,EAAE,MAAM,CAAC,MAAM;aAAC;QAE3HD,QAAQ,OAAO,CAACC,CAAAA;YACZ,MAAMiB,qBAAqBF,qBAAqB,GAAG,CAACf,EAAE,MAAM,IAAKA,EAAE,MAAM,CAAC,MAAM;YAEhFA,EAAE,MAAM,CAAC,MAAM,CAACA,EAAE,KAAK,GAAGiB,oBAAoB;QAClD;IACJ,OAAO;QACH,MAAMb,cAAenB,QAAsC,IAAI;QAE/D,MAAM,IAAIoB,MAAM,CAAC,+GAA+G,EAAED,YAAY,CAAC,CAAC;IACpJ;AACJ"}
|
|
1
|
+
{"version":3,"file":"transformers/moduleRules.js","sources":["webpack://@workleap/webpack-configs/./src/transformers/moduleRules.ts"],"sourcesContent":["import path from \"node:path\";\nimport type { RuleSetRule, RuleSetUseItem } from \"webpack\";\nimport type { WebpackConfig } from \"../types.ts\";\n\nexport type ModuleRuleMatcher = (moduleRule: RuleSetRule | RuleSetUseItem, index: number, array: RuleSetRule[] | RuleSetUseItem[]) => boolean;\n\nexport type WithModuleRuleMatcherInfo = {\n info: {\n type: string;\n value: string;\n };\n} & ModuleRuleMatcher;\n\nfunction isNameMatchingLoader(loader: string, name: string) {\n return loader === name || loader.includes(`${path.sep}${name}${path.sep}`) || loader.includes(`@${name}${path.sep}`);\n}\n\nexport function matchLoaderName(name: string): ModuleRuleMatcher {\n const matcher: WithModuleRuleMatcherInfo = moduleRule => {\n if (typeof moduleRule === \"string\") {\n return isNameMatchingLoader(moduleRule, name);\n } else {\n if (\"loader\" in moduleRule && moduleRule.loader) {\n return isNameMatchingLoader(moduleRule.loader, name);\n }\n }\n\n return false;\n };\n\n // Add contextual information about the matcher for debugging.\n matcher.info = {\n type: matchLoaderName.name,\n value: name\n };\n\n return matcher;\n}\n\nexport type AssetModuleType =\n | \"javascript/auto\"\n | \"javascript/dynamic\"\n | \"javascript/esm\"\n | \"json\"\n | \"webassembly/sync\"\n | \"webassembly/async\"\n | \"asset\"\n | \"asset/source\"\n | \"asset/resource\"\n | \"asset/inline\";\n\nexport function matchAssetModuleType(type: AssetModuleType): ModuleRuleMatcher {\n const matcher: WithModuleRuleMatcherInfo = moduleRule => {\n if (typeof moduleRule !== \"string\" && \"type\" in moduleRule) {\n return moduleRule.type === type;\n }\n\n return false;\n };\n\n // Add contextual information about the matcher for debugging.\n matcher.info = {\n type: matchAssetModuleType.name,\n value: type\n };\n\n return matcher;\n}\n\nexport function matchTest(test: string | RegExp): ModuleRuleMatcher {\n const matcher: WithModuleRuleMatcherInfo = moduleRule => {\n if (typeof moduleRule !== \"string\" && \"test\" in moduleRule) {\n if (typeof moduleRule.test === \"object\" && typeof test === \"object\") {\n // Assuming it's regular expressions.\n return moduleRule.test.toString() === test.toString();\n }\n\n return moduleRule.test === test;\n }\n\n return false;\n };\n\n // Add contextual information about the matcher for debugging.\n matcher.info = {\n type: matchTest.name,\n value: test.toString()\n };\n\n return matcher;\n}\n\nexport interface ModuleRuleMatch {\n moduleRule: RuleSetRule | RuleSetUseItem;\n index: number;\n parent: RuleSetRule[] | RuleSetUseItem[];\n}\n\nfunction toMatch(moduleRule: RuleSetRule | RuleSetUseItem, index: number, parent: RuleSetRule[] | RuleSetUseItem[]) {\n return {\n moduleRule,\n index,\n parent\n };\n}\n\nfunction isRuleSetRule(value: RuleSetRule | RuleSetUseItem): value is RuleSetRule {\n return (value as RuleSetRule).use !== undefined || (value as RuleSetRule).oneOf !== undefined;\n}\n\nfunction findModuleRulesRecursively(moduleRules: RuleSetRule[] | RuleSetUseItem[], matcher: ModuleRuleMatcher, parent: RuleSetRule[] | RuleSetUseItem[], matches: ModuleRuleMatch[]) {\n moduleRules.forEach((x, index, array) => {\n if (x) {\n if (matcher(x, index, array)) {\n matches.push(toMatch(x, index, parent));\n } else {\n if (isRuleSetRule(x)) {\n if (x.use) {\n findModuleRulesRecursively(x.use as RuleSetUseItem[], matcher, x.use as RuleSetUseItem[], matches);\n } else if (x.oneOf) {\n // This error seems to have been introduced by either TS 5.2. or webpack 5.88.1 (https://github.com/webpack/webpack/releases/tag/v5.88.1),\n // I am not sure what changed thought.\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n findModuleRulesRecursively(x.oneOf, matcher, x.oneOf, matches);\n }\n }\n }\n }\n });\n}\n\nexport function findModuleRule(config: WebpackConfig, matcher: ModuleRuleMatcher) {\n const moduleRules = config.module?.rules;\n\n if (!moduleRules) {\n return;\n }\n\n const matches: ModuleRuleMatch[] = [];\n\n findModuleRulesRecursively(moduleRules as RuleSetRule[], matcher, moduleRules as RuleSetRule[], matches);\n\n if (matches.length > 1) {\n const matcherInfo = (matcher as WithModuleRuleMatcherInfo).info;\n\n throw new Error(`[webpack-configs] Found more than 1 matching module rule.\\n[webpack-configs] Matcher: \"${JSON.stringify(matcherInfo)}\"\\n[webpack-configs] Matches: \"${JSON.stringify(matches.map(x => x.moduleRule))}\"`);\n }\n\n return matches[0];\n}\n\nexport function findModuleRules(config: WebpackConfig, matcher: ModuleRuleMatcher) {\n const moduleRules = config.module?.rules;\n\n if (!moduleRules) {\n return;\n }\n\n const matches: ModuleRuleMatch[] = [];\n\n findModuleRulesRecursively(moduleRules as RuleSetRule[], matcher, moduleRules as RuleSetRule[], matches);\n\n return matches;\n}\n\nexport function addBeforeModuleRule(config: WebpackConfig, matcher: ModuleRuleMatcher, newModuleRules: RuleSetRule[] | RuleSetUseItem[]) {\n const match = findModuleRule(config, matcher);\n\n if (match) {\n match.parent.splice(match.index, 0, ...newModuleRules);\n } else {\n const matcherInfo = (matcher as WithModuleRuleMatcherInfo).info;\n\n throw new Error(`[webpack-configs] Couldn't add the new module rules because no match has been found.\\n[webpack-configs] Matcher: \"${JSON.stringify(matcherInfo)}\"`);\n }\n}\n\nexport function addAfterModuleRule(config: WebpackConfig, matcher: ModuleRuleMatcher, newModuleRules: RuleSetRule[] | RuleSetUseItem[]) {\n const match = findModuleRule(config, matcher);\n\n if (match) {\n match.parent.splice(match.index + 1, 0, ...newModuleRules);\n } else {\n const matcherInfo = (matcher as WithModuleRuleMatcherInfo).info;\n\n throw new Error(`[webpack-configs] Couldn't add the new module rules because no match has been found.\\n[webpack-configs] Matcher: \"${JSON.stringify(matcherInfo)}\"`);\n }\n}\n\nexport function replaceModuleRule(config: WebpackConfig, matcher: ModuleRuleMatcher, newModuleRule: RuleSetRule | RuleSetUseItem) {\n const match = findModuleRule(config, matcher);\n\n if (match) {\n match.parent[match.index] = newModuleRule;\n } else {\n const matcherInfo = (matcher as WithModuleRuleMatcherInfo).info;\n\n throw new Error(`[webpack-configs] Couldn't replace the module rule because no match has been found.\\n[webpack-configs] Matcher: \"${JSON.stringify(matcherInfo)}\"`);\n }\n}\n\nexport function removeModuleRules(config: WebpackConfig, matcher: ModuleRuleMatcher) {\n const moduleRules = config.module?.rules;\n\n if (!moduleRules) {\n return;\n }\n\n const matches: ModuleRuleMatch[] = [];\n\n findModuleRulesRecursively(moduleRules as RuleSetRule[], matcher, moduleRules as RuleSetRule[], matches);\n\n if (matches.length > 0) {\n // Must keep the initial parent arrays' length to calculate the adjustment\n // once the first match has been deleted.\n const initialParentLengths = new Map<RuleSetRule[] | RuleSetUseItem[], number>(matches.map(x => [x.parent, x.parent.length]));\n\n matches.forEach(x => {\n const positionAdjustment = initialParentLengths.get(x.parent)! - x.parent.length;\n\n x.parent.splice(x.index - positionAdjustment, 1);\n });\n } else {\n const matcherInfo = (matcher as WithModuleRuleMatcherInfo).info;\n\n throw new Error(`[webpack-configs] Didn't remove any module rules because no match has been found.\\n[webpack-configs] Matcher: \"${matcherInfo}\"`);\n }\n}\n"],"names":["path","isNameMatchingLoader","loader","name","matchLoaderName","matcher","moduleRule","matchAssetModuleType","type","matchTest","test","toMatch","index","parent","isRuleSetRule","value","undefined","findModuleRulesRecursively","moduleRules","matches","x","array","findModuleRule","config","matcherInfo","Error","JSON","findModuleRules","addBeforeModuleRule","newModuleRules","match","addAfterModuleR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ACtK;AACJ;AAEO,SAASU,kBAAkBX,MAAqB,EAAElB,OAA0B;IAC/E,MAAMa,cAAcK,OAAO,MAAM,EAAE;IAEnC,IAAI,CAACL,aAAa;QACd;IACJ;IAEA,MAAMC,UAA6B,EAAE;IAErCF,2BAA2BC,aAA8Bb,SAASa,aAA8BC;IAEhG,IAAIA,QAAQ,MAAM,GAAG,GAAG;QACpB,0EAA0E;QAC1E,yCAAyC;QACzC,MAAMgB,uBAAuB,IAAIC,IAA8CjB,QAAQ,GAAG,CAACC,CAAAA,IAAK;gBAACA,EAAE,MAAM;gBAAEA,EAAE,MAAM,CAAC,MAAM;aAAC;QAE3HD,QAAQ,OAAO,CAACC,CAAAA;YACZ,MAAMiB,qBAAqBF,qBAAqB,GAAG,CAACf,EAAE,MAAM,IAAKA,EAAE,MAAM,CAAC,MAAM;YAEhFA,EAAE,MAAM,CAAC,MAAM,CAACA,EAAE,KAAK,GAAGiB,oBAAoB;QAClD;IACJ,OAAO;QACH,MAAMb,cAAenB,QAAsC,IAAI;QAE/D,MAAM,IAAIoB,MAAM,CAAC,+GAA+G,EAAED,YAAY,CAAC,CAAC;IACpJ;AACJ"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@workleap/webpack-configs",
|
|
3
3
|
"author": "Workleap",
|
|
4
4
|
"description": "Workleap recommended webpack configurations.",
|
|
5
|
-
"version": "1.6.
|
|
5
|
+
"version": "1.6.3",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -24,15 +24,14 @@
|
|
|
24
24
|
"files": [
|
|
25
25
|
"src",
|
|
26
26
|
"dist",
|
|
27
|
-
"CHANGELOG.md"
|
|
28
|
-
"README.md"
|
|
27
|
+
"CHANGELOG.md"
|
|
29
28
|
],
|
|
30
29
|
"peerDependencies": {
|
|
31
|
-
"@swc/core": "^1.
|
|
30
|
+
"@swc/core": "^1.13.5",
|
|
32
31
|
"@swc/helpers": "^0.5.17",
|
|
33
|
-
"browserslist": "^4.
|
|
32
|
+
"browserslist": "^4.27.0",
|
|
34
33
|
"postcss": "^8.5.6",
|
|
35
|
-
"webpack": "^5.
|
|
34
|
+
"webpack": "^5.102.1",
|
|
36
35
|
"webpack-dev-server": "^5.2.2"
|
|
37
36
|
},
|
|
38
37
|
"peerDependenciesMeta": {
|
|
@@ -44,27 +43,29 @@
|
|
|
44
43
|
"@pmmmwh/react-refresh-webpack-plugin": "^0.6.1",
|
|
45
44
|
"@svgr/webpack": "^8.1.0",
|
|
46
45
|
"css-loader": "^7.1.2",
|
|
47
|
-
"html-webpack-plugin": "^5.6.
|
|
48
|
-
"mini-css-extract-plugin": "^2.9.
|
|
49
|
-
"postcss-loader": "^8.
|
|
50
|
-
"react-refresh": "^0.
|
|
46
|
+
"html-webpack-plugin": "^5.6.4",
|
|
47
|
+
"mini-css-extract-plugin": "^2.9.4",
|
|
48
|
+
"postcss-loader": "^8.2.0",
|
|
49
|
+
"react-refresh": "^0.18.0",
|
|
51
50
|
"style-loader": "^4.0.0",
|
|
52
51
|
"swc-loader": "^0.2.6",
|
|
53
52
|
"terser-webpack-plugin": "^5.3.14"
|
|
54
53
|
},
|
|
55
54
|
"devDependencies": {
|
|
56
|
-
"@
|
|
57
|
-
"@
|
|
55
|
+
"@eslint/js": "9.38.0",
|
|
56
|
+
"@rsbuild/core": "1.5.17",
|
|
57
|
+
"@rslib/core": "0.16.0",
|
|
58
58
|
"@svgr/core": "8.1.0",
|
|
59
|
-
"@types/node": "24.
|
|
60
|
-
"@typescript-eslint/parser": "8.
|
|
61
|
-
"eslint": "
|
|
62
|
-
"typescript": "5.
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"@workleap/
|
|
66
|
-
"@workleap/
|
|
67
|
-
"@workleap/
|
|
59
|
+
"@types/node": "24.9.1",
|
|
60
|
+
"@typescript-eslint/parser": "8.46.2",
|
|
61
|
+
"eslint": "9.38.0",
|
|
62
|
+
"typescript": "5.9.3",
|
|
63
|
+
"typescript-eslint": "8.46.2",
|
|
64
|
+
"vitest": "4.0.1",
|
|
65
|
+
"@workleap/eslint-configs": "0.0.3",
|
|
66
|
+
"@workleap/rslib-configs": "1.1.3",
|
|
67
|
+
"@workleap/swc-configs": "2.3.3",
|
|
68
|
+
"@workleap/typescript-configs": "3.0.7"
|
|
68
69
|
},
|
|
69
70
|
"scripts": {
|
|
70
71
|
"build": "rslib build -c rslib.config.ts",
|
|
@@ -12,7 +12,7 @@ export type WithModuleRuleMatcherInfo = {
|
|
|
12
12
|
} & ModuleRuleMatcher;
|
|
13
13
|
|
|
14
14
|
function isNameMatchingLoader(loader: string, name: string) {
|
|
15
|
-
return loader === name || loader.
|
|
15
|
+
return loader === name || loader.includes(`${path.sep}${name}${path.sep}`) || loader.includes(`@${name}${path.sep}`);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export function matchLoaderName(name: string): ModuleRuleMatcher {
|
|
@@ -38,16 +38,16 @@ export function matchLoaderName(name: string): ModuleRuleMatcher {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
export type AssetModuleType =
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
41
|
+
| "javascript/auto"
|
|
42
|
+
| "javascript/dynamic"
|
|
43
|
+
| "javascript/esm"
|
|
44
|
+
| "json"
|
|
45
|
+
| "webassembly/sync"
|
|
46
|
+
| "webassembly/async"
|
|
47
|
+
| "asset"
|
|
48
|
+
| "asset/source"
|
|
49
|
+
| "asset/resource"
|
|
50
|
+
| "asset/inline";
|
|
51
51
|
|
|
52
52
|
export function matchAssetModuleType(type: AssetModuleType): ModuleRuleMatcher {
|
|
53
53
|
const matcher: WithModuleRuleMatcherInfo = moduleRule => {
|