Skip to content

Commit

Permalink
feat(builder): bump webpack v5.88, support top level await (#4102)
Browse files Browse the repository at this point in the history
* feat(builder): bump webpack v5.88, support top level await

* docs: fix

* chore: fix rule type

* chore: fix type issue
  • Loading branch information
chenjiahan committed Jun 30, 2023
1 parent a44aac7 commit 272646c
Show file tree
Hide file tree
Showing 28 changed files with 482 additions and 228 deletions.
21 changes: 21 additions & 0 deletions .changeset/short-trees-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
'@modern-js/builder-webpack-provider': patch
'@modern-js/builder-rspack-provider': patch
'@modern-js/builder-plugin-image-compress': patch
'@modern-js/builder-shared': patch
'@modern-js/plugin-data-loader': patch
'@modern-js/runtime': patch
'@modern-js/builder-plugin-stylus': patch
'@modern-js/plugin-storybook': patch
'@modern-js/app-tools': patch
'@modern-js/builder-plugin-swc': patch
'@modern-js/builder-plugin-vue': patch
'@modern-js/plugin-bff': patch
'@modern-js/server': patch
'@modern-js/utils': patch
'@modern-js/doc-core': patch
---

feat(builder): bump webpack v5.88, support top level await

feat(builder): 升级 webpack v5.88, 支持 top level await
2 changes: 1 addition & 1 deletion packages/builder/builder-rspack-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"react-refresh": "0.14.0",
"rspack-plugin-virtual-module": "0.1.0",
"style-loader": "3.3.1",
"webpack": "^5.82.1"
"webpack": "^5.88.1"
},
"devDependencies": {
"@arco-design/web-react": "^2.46.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/builder/builder-rspack-provider/tests/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const getBuilderPlugins = async () => {
/** Match plugin by constructor name. */
export const matchPlugin = (config: RspackConfig, pluginName: string) => {
const result = config.plugins?.filter(
item => item.constructor.name === pluginName,
item => item?.constructor.name === pluginName,
);

if (Array.isArray(result)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/builder/builder-shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
"line-diff": "^2.0.1",
"postcss": "8.4.21",
"source-map": "^0.7.4",
"webpack": "^5.82.1",
"webpack": "^5.88.1",
"webpack-sources": "^3.2.3",
"zod": "^3.20.2",
"zod-validation-error": "1.2.0"
Expand Down
15 changes: 12 additions & 3 deletions packages/builder/builder-shared/src/fallback.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { JS_REGEX, TS_REGEX } from './constants';
import type { RuleSetRule } from 'webpack';

type Rules = (undefined | null | false | '' | 0 | RuleSetRule | '...')[];

export const resourceRuleFallback = (
rules: Array<RuleSetRule | '...'> = [],
rules: Rules = [],
): Array<RuleSetRule | '...'> => {
const innerRules: Array<RuleSetRule> = [];
const innerRules: RuleSetRule[] = [];
const outerRules: Array<RuleSetRule | '...'> = [];

for (const rule of rules) {
if (!rule) {
continue;
}
if (
// "..." refers to the webpack defaults
rule === '...' ||
Expand All @@ -25,7 +30,11 @@ export const resourceRuleFallback = (
rule.mimetype
)
) {
rule.oneOf.forEach(r => innerRules.push(r));
rule.oneOf.forEach(item => {
if (item) {
innerRules.push(item);
}
});
} else {
innerRules.push(rule);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/builder/builder-webpack-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
"style-loader": "3.3.1",
"terser-webpack-plugin": "5.3.6",
"ts-loader": "9.4.1",
"webpack": "^5.82.1"
"webpack": "^5.88.1"
},
"devDependencies": {
"@arco-design/web-react": "^2.46.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ async function getConfigUtils(
removePlugin(pluginName: string) {
if (config.plugins) {
config.plugins = config.plugins.filter(
p => p.constructor.name !== pluginName,
item => item?.constructor.name !== pluginName,
);
}
},
Expand Down
4 changes: 2 additions & 2 deletions packages/builder/builder-webpack-provider/src/plugins/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const builderPluginCopy = (): BuilderPlugin => ({

api.modifyWebpackConfig(async config => {
const copyPlugin = config.plugins?.find(
item => item.constructor.name === 'CopyPlugin',
item => item?.constructor.name === 'CopyPlugin',
) as unknown as CopyPluginOptions;

if (copyPlugin) {
Expand All @@ -41,7 +41,7 @@ export const builderPluginCopy = (): BuilderPlugin => ({
);
if (isContextNotExists) {
config.plugins = config.plugins?.filter(
item => item.constructor.name !== 'CopyPlugin',
item => item?.constructor.name !== 'CopyPlugin',
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export async function createStubBuilder(options?: StubBuilderOptions) {
const matchWebpackPlugin = async (pluginName: string) => {
const config = await unwrapWebpackConfig();
const result = config.plugins?.filter(
item => item.constructor.name === pluginName,
item => item?.constructor.name === pluginName,
);
if (Array.isArray(result)) {
assert(result.length <= 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export function matchLoader({
}
return config.module.rules.some(rule => {
if (
rule &&
typeof rule === 'object' &&
rule.test &&
rule.test instanceof RegExp &&
Expand Down
2 changes: 1 addition & 1 deletion packages/builder/plugin-image-compress/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"@scripts/vitest-config": "workspace:*",
"@types/node": "^14",
"typescript": "^5",
"webpack": "^5.82.1"
"webpack": "^5.88.1"
},
"sideEffects": false,
"publishConfig": {
Expand Down
2 changes: 1 addition & 1 deletion packages/builder/plugin-stylus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@modern-js/utils": "workspace:*",
"@scripts/vitest-config": "workspace:*",
"typescript": "^5",
"webpack": "^5.82.1"
"webpack": "^5.88.1"
},
"peerDependencies": {
"@modern-js/builder-rspack-provider": "workspace:^2.25.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/builder/plugin-swc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"magic-string": "0.29.0",
"source-map": "^0.7.4",
"typescript": "^5",
"webpack": "^5.82.1",
"webpack": "^5.88.1",
"react": "^18",
"react-dom": "^18"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/builder/plugin-vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@modern-js/utils": "workspace:*",
"@scripts/vitest-config": "workspace:*",
"typescript": "^5",
"webpack": "^5.82.1"
"webpack": "^5.88.1"
},
"peerDependencies": {
"@modern-js/builder-webpack-provider": "workspace:^2.25.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/doc-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
"typescript": "^5",
"vite": "^4.0.4",
"vitest": "0.21.1",
"webpack": "^5.82.1",
"webpack": "^5.88.1",
"gray-matter": "4.0.3"
},
"sideEffects": [
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/plugin-bff/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"memfs": "^3.3.0",
"ts-jest": "^29.1.0",
"typescript": "^5",
"webpack": "^5.82.1",
"webpack": "^5.88.1",
"webpack-chain": "^6.5.1"
},
"sideEffects": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/plugin-data-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"supertest": "^6.1.6",
"ts-jest": "^29.1.0",
"typescript": "^5",
"webpack": "^5.82.1",
"webpack": "^5.88.1",
"webpack-chain": "^6.5.1",
"react": "^18",
"react-dom": "^18"
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/plugin-storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"react-dom": "^17.0.2",
"require-from-string": "^2.0.2",
"typescript": "^5",
"webpack": "^5.82.1",
"webpack": "^5.88.1",
"webpack-chain": "^6.5.1"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/plugin-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
"react-dom": "^18",
"ts-jest": "^29.1.0",
"typescript": "^5",
"webpack": "^5.82.1"
"webpack": "^5.88.1"
},
"sideEffects": false,
"modernConfig": {},
Expand Down
2 changes: 1 addition & 1 deletion packages/server/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"ts-node": "^10.9.1",
"tsconfig-paths": "4.1.1",
"typescript": "^5",
"webpack": "^5.82.1",
"webpack": "^5.88.1",
"websocket": "^1"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/solutions/app-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"@types/node": "^14",
"jest": "^29",
"typescript": "^5",
"webpack": "^5.82.1"
"webpack": "^5.88.1"
},
"peerDependencies": {
"@modern-js/builder-rspack-provider": "workspace:^2.25.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/toolkit/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@
"@types/node": "^14",
"jest": "^29",
"typescript": "^5",
"webpack": "^5.82.1",
"webpack": "^5.88.1",
"@types/serialize-javascript": "^5.0.1"
},
"sideEffects": false
Expand Down

0 comments on commit 272646c

Please sign in to comment.