Skip to content

Commit 018d03c

Browse files
Merge pull request #1740 from docschina/sync-d054d465-1
docs(en): merge webpack.js.org/sync-loader-plugin into webpack.js.org/cn @ d054d46
2 parents cbefd7b + 00352d5 commit 018d03c

File tree

5 files changed

+619
-945
lines changed

5 files changed

+619
-945
lines changed

package.json

Lines changed: 53 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@
2828
"clean-printable": "rimraf src/content/**/printable.mdx",
2929
"preclean": "run-s clean-dist clean-printable",
3030
"clean": "rimraf src/content/**/_*.mdx src/**/_*.json repositories/*.json",
31-
"start": "npm run clean-dist && webpack serve --config webpack.dev.mjs --env dev --progress --node-env development",
31+
"start": "npm run clean-dist && webpack serve --config webpack.dev.mjs --env dev --progress --define-process-env-node-env development",
3232
"content": "node src/scripts/build-content-tree.mjs ./src/content ./src/_content.json",
33-
"bundle-analyze": "run-s clean fetch content && webpack --config webpack.prod.mjs --node-env production && run-s printable content && webpack --config webpack.ssg.mjs --node-env production --env ssg --profile --json > stats.json && webpack-bundle-analyzer stats.json",
33+
"bundle-analyze": "run-s clean fetch content && webpack --config webpack.prod.mjs --define-process-env-node-env production && run-s printable content && webpack --config webpack.ssg.mjs --define-process-env-node-env production --env ssg --profile --json > stats.json && webpack-bundle-analyzer stats.json",
3434
"fetch-repos": "node src/utilities/fetch-package-repos.mjs",
3535
"fetch": "run-p fetch:*",
3636
"fetch:readmes": "node src/utilities/fetch-package-readmes.mjs",
3737
"fetch:supporters": "node src/utilities/fetch-supporters.mjs",
3838
"prebuild": "npm run clean",
39-
"build": "run-s content && webpack --config webpack.prod.mjs --node-env production && run-s printable content && webpack --config webpack.ssg.mjs --node-env production --env ssg",
39+
"build": "run-s fetch-repos fetch content && webpack --config webpack.prod.mjs --define-process-env-node-env production && run-s printable content && webpack --config webpack.ssg.mjs --define-process-env-node-env production --env ssg",
4040
"postbuild": "npm run sitemap",
4141
"build-test": "npm run build && http-server --port 4200 dist/",
4242
"serve-dist": "http-server --port 4200 dist/",
@@ -48,9 +48,6 @@
4848
"lint-markdown": "markdownlint --config ./.markdownlint.json",
4949
"lint:prose": "vale --config='.vale.ini' src/content",
5050
"lint:links": "hyperlink -c 8 --root dist -r dist/index.html --canonicalroot https://webpack.js.org/ --internal --skip /plugins/extract-text-webpack-plugin/ --skip /printable --skip https:// --skip http:// --skip sw.js > internal-links.tap; cat internal-links.tap | tap-spot",
51-
"lint:heading": "textlint --fix src/content/*",
52-
"lint:heading-blog": "textlint --fix src/content/blog/*",
53-
"lint:headingMDX": "textlint --fix src/content/**/*.mdx",
5451
"sitemap": "cd dist && sitemap-static --ignore-file=../sitemap-ignore.json --pretty --prefix=https://webpack.js.org/ > sitemap.xml",
5552
"serve": "npm run build && sirv start ./dist --port 4000",
5653
"preprintable": "npm run clean-printable",
@@ -73,102 +70,97 @@
7370
]
7471
},
7572
"devDependencies": {
76-
"@babel/core": "^7.19.6",
77-
"@babel/eslint-parser": "^7.19.1",
73+
"@babel/core": "^7.22.19",
74+
"@babel/eslint-parser": "^7.22.15",
7875
"@babel/plugin-proposal-class-properties": "^7.17.12",
79-
"@babel/preset-env": "^7.19.4",
80-
"@babel/preset-react": "^7.18.6",
76+
"@babel/preset-env": "^7.22.15",
77+
"@babel/preset-react": "^7.22.15",
8178
"@mdx-js/loader": "^2.0.0-next.9",
82-
"@octokit/auth-action": "^2.0.2",
83-
"@octokit/rest": "^19.0.5",
79+
"@octokit/auth-action": "^4.0.0",
80+
"@octokit/rest": "^20.0.1",
8481
"@pmmmwh/react-refresh-webpack-plugin": "next",
85-
"@svgr/webpack": "^6.5.1",
86-
"autoprefixer": "^10.4.13",
87-
"babel-loader": "^9.0.0",
82+
"@svgr/webpack": "^8.1.0",
83+
"autoprefixer": "^10.4.15",
84+
"babel-loader": "^9.1.3",
8885
"copy-webpack-plugin": "^11.0.0",
89-
"css-loader": "^6.7.1",
90-
"css-minimizer-webpack-plugin": "^4.2.2",
91-
"cypress": "^10.11.0",
92-
"directory-tree": "^3.3.1",
86+
"css-loader": "^6.8.1",
87+
"css-minimizer-webpack-plugin": "^5.0.1",
88+
"cypress": "^13.2.0",
89+
"directory-tree": "^3.5.1",
9390
"directory-tree-webpack-plugin": "^1.0.3",
9491
"duplexer": "^0.1.1",
95-
"eslint": "^8.26.0",
96-
"eslint-config-prettier": "^8.5.0",
97-
"eslint-plugin-cypress": "^2.12.1",
98-
"eslint-plugin-mdx": "^2.0.5",
99-
"eslint-plugin-react": "^7.31.10",
92+
"eslint": "^8.49.0",
93+
"eslint-config-prettier": "^9.0.0",
94+
"eslint-plugin-cypress": "^2.14.0",
95+
"eslint-plugin-mdx": "^2.2.0",
96+
"eslint-plugin-react": "^7.33.2",
10097
"eslint-plugin-react-hooks": "^4.6.0",
10198
"front-matter": "^4.0.2",
10299
"github-slugger": "^2.0.0",
103-
"html-loader": "^2.1.2",
104-
"html-webpack-plugin": "^5.5.0",
100+
"html-webpack-plugin": "^5.5.3",
105101
"http-server": "^14.1.1",
106-
"husky": "^8.0.1",
102+
"husky": "^8.0.3",
107103
"hyperlink": "^5.0.4",
108104
"jest": "^29.7.0",
109-
"lightningcss": "^1.16.0",
110-
"lint-staged": "^13.0.3",
105+
"lightningcss": "^1.21.8",
106+
"lint-staged": "^14.0.1",
111107
"lodash": "^4.17.21",
112-
"markdownlint": "^0.26.2",
113-
"markdownlint-cli": "^0.32.2",
114-
"mdast-util-to-string": "^3.1.0",
115-
"mini-css-extract-plugin": "^2.6.1",
116-
"mkdirp": "^1.0.4",
108+
"markdownlint-cli": "^0.36.0",
109+
"mdast-util-to-string": "^4.0.0",
110+
"mini-css-extract-plugin": "^2.7.6",
111+
"mkdirp": "^3.0.1",
117112
"modularscale-sass": "^3.0.3",
118-
"node-fetch": "^3.2.10",
119113
"npm-run-all": "^4.1.1",
120-
"postcss": "^8.4.18",
121-
"postcss-loader": "^7.0.1",
122-
"prettier": "^2.7.1",
114+
"postcss": "^8.4.29",
115+
"postcss-loader": "^7.3.3",
116+
"prettier": "^3.0.3",
123117
"react-refresh": "^0.14.0",
124118
"redirect-webpack-plugin": "^1.0.0",
125-
"remark": "^14.0.2",
119+
"remark": "^14.0.3",
126120
"remark-autolink-headings": "7.0.1",
127-
"remark-emoji": "^3.0.2",
121+
"remark-emoji": "^4.0.0",
128122
"remark-extract-anchors": "1.1.1",
129123
"remark-frontmatter": "^4.0.1",
130124
"remark-gfm": "^1.0.0",
131-
"remark-html": "^15.0.1",
125+
"remark-html": "^15.0.2",
132126
"remark-refractor": "montogeek/remark-refractor",
133-
"rimraf": "^3.0.2",
134-
"sass": "^1.55.0",
135-
"sass-loader": "^13.1.0",
127+
"rimraf": "^5.0.1",
128+
"sass": "^1.67.0",
129+
"sass-loader": "^13.3.2",
136130
"sirv-cli": "^2.0.2",
137131
"sitemap-static": "^0.4.2",
138132
"static-site-generator-webpack-plugin": "^3.4.1",
139-
"style-loader": "^3.3.1",
140-
"tailwindcss": "^3.2.1",
133+
"style-loader": "^3.3.3",
134+
"tailwindcss": "^3.3.3",
141135
"tap-spot": "^1.1.2",
142-
"textlint": "^11.8.2",
143-
"textlint-rule-heading": "^1.0.10",
144-
"unist-util-visit": "^4.1.1",
145-
"webpack": "^5.74.0",
146-
"webpack-bundle-analyzer": "^4.7.0",
147-
"webpack-cli": "^4.10.0",
148-
"webpack-dev-server": "^4.11.1",
149-
"webpack-merge": "^5.8.0",
150-
"workbox-webpack-plugin": "^6.5.4",
151-
"yarn-deduplicate": "^6.0.0"
136+
"unist-util-visit": "^5.0.0",
137+
"webpack": "^5.88.2",
138+
"webpack-bundle-analyzer": "^4.9.1",
139+
"webpack-cli": "^5.1.4",
140+
"webpack-dev-server": "^4.15.1",
141+
"webpack-merge": "^5.9.0",
142+
"workbox-webpack-plugin": "^7.0.0",
143+
"yarn-deduplicate": "^6.0.2"
152144
},
153145
"dependencies": {
154146
"@docsearch/react": "^3.0.0-alpha.50",
147+
"@react-spring/web": "^9.7.3",
155148
"path-browserify": "^1.0.1",
156149
"prop-types": "^15.8.1",
157150
"react": "^17.0.2",
158151
"react-dom": "^17.0.2",
159152
"react-helmet-async": "^1.3.0",
160-
"react-router-dom": "^6.4.2",
161-
"react-spring": "^9.5.5",
153+
"react-router-dom": "^6.16.0",
162154
"react-tiny-popover": "5",
163155
"react-use": "^17.4.0",
164156
"react-visibility-sensor": "^5.0.2",
165157
"webpack-pwa-manifest": "^4.3.0",
166-
"webpack.vote": "https://github.com/webpack/voting-app.git",
167-
"workbox-window": "^6.5.4"
158+
"workbox-window": "^7.0.0"
168159
},
169160
"resolutions": {
170161
"sitemap-static/minimist": "1.2.5",
171162
"ini": "1.3.7",
172-
"eval": "^0.1.5"
163+
"eval": "^0.1.5",
164+
"markdownlint-cli/markdownlint": "^0.27.0"
173165
}
174166
}

src/content/guides/typescript.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ module.exports = {
117117
document.body.appendChild(component());
118118
```
119119

120-
T> 如果想在 TypeScript 中继续使用像 `import _ from 'lodash';` 的语法,让它被作为一种默认的导入方式,需要在 **tsconfig.json** 中设置 `"allowSyntheticDefaultImports" : true``"esModuleInterop" : true`。这是与 TypeScript 相关的配置,在本文档中提及仅供参考。
120+
T> 如果想在 TypeScript 中保留如 `import _ from 'lodash';` 的语法让它被作为一种默认的导入方式,需要在文件 **tsconfig.json** 中设置 `"allowSyntheticDefaultImports" : true``"esModuleInterop" : true`。这是与 TypeScript 相关的配置,在本文档中提及仅供参考。
121121

122122
## loader $#loader$
123123

src/content/plugins/image-minimizer-webpack-plugin.mdx

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ module.exports = {
283283
| **[`minify`](#minify)** | `{Function \| Array<Function>}` | `ImageMinimizerPlugin.imageminMinify` | Allows to override default minify function |
284284
| **[`minimizerOptions`](#minimizeroptions)** | `{Object\|Array<Object>}` | `{ plugins: [] }` | Options for `imagemin` |
285285
| **[`loader`](#loader)** | `{Boolean}` | `true` | Automatically adding `imagemin-loader` |
286-
| **[`maxConcurrency`](#maxconcurrency)** | `{Number}` | `Math.max(1, os.cpus().length - 1)` | Maximum number of concurrency optimization processes in one time |
286+
| **[`concurrency`](#concurrency)** | `{Number}` | `Math.max(1, os.cpus().length - 1)` | Maximum number of concurrency optimization processes in one time |
287287
| **[`filename`](#filename)** | `{string\|Function}` | `'[path][name][ext]'` | Allows to set the filename for the generated asset. Useful for converting to a `webp` |
288288
| **[`deleteOriginalAssets`](#deleteoriginalassets)** | `{Boolean}` | `false` | Allows to delete the original asset. Useful for converting to a `webp` and remove original assets |
289289

@@ -610,7 +610,7 @@ module.exports = {
610610
};
611611
```
612612

613-
#### `maxConcurrency`
613+
#### `concurrency`
614614

615615
Type: `Number`
616616
Default: `Math.max(1, os.cpus().length - 1)`
@@ -625,7 +625,7 @@ const ImageMinimizerPlugin = require("image-minimizer-webpack-plugin");
625625
module.exports = {
626626
plugins: [
627627
new ImageMinimizerPlugin({
628-
maxConcurrency: 3,
628+
concurrency: 3,
629629
}),
630630
],
631631
};
@@ -1230,17 +1230,6 @@ The function normalizes configuration (converts plugins names and options to `Fu
12301230
```js
12311231
const imagemin = require("imagemin");
12321232
const { imageminNormalizeConfig } = require("image-minimizer-webpack-plugin");
1233-
const imageminConfig = imageminNormalizeConfig({
1234-
plugins: [
1235-
"jpegtran",
1236-
[
1237-
"pngquant",
1238-
{
1239-
quality: [0.6, 0.8],
1240-
},
1241-
],
1242-
],
1243-
});
12441233

12451234
/*
12461235
console.log(imageminConfig);
@@ -1255,6 +1244,9 @@ const imageminConfig = imageminNormalizeConfig({
12551244
*/
12561245

12571246
(async () => {
1247+
const imageminConfig = await imageminNormalizeConfig({
1248+
plugins: ["jpegtran", ["pngquant", { quality: [0.6, 0.8] }]],
1249+
});
12581250
const files = await imagemin(["images/*.{jpg,png}"], {
12591251
destination: "build/images",
12601252
plugins: imageminConfig.plugins,

src/utilities/fetch-package-readmes.mjs

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import _ from 'lodash';
22
import fs from 'fs';
33
import path from 'path';
44
import { promisify } from 'util';
5-
import mkdirp from 'mkdirp';
6-
import fetch from 'node-fetch';
5+
import { mkdirp } from 'mkdirp';
76
import { fileURLToPath } from 'url';
7+
import api from './githubAPI.mjs';
88

99
import yamlHeadmatter from './yaml-headmatter.mjs';
1010
import processReadme from './process-readme.mjs';
@@ -13,7 +13,6 @@ const __filename = fileURLToPath(import.meta.url);
1313
const __dirname = path.dirname(__filename);
1414

1515
const writeFile = promisify(fs.writeFile);
16-
const rename = promisify(fs.rename);
1716
const readFile = promisify(fs.readFile);
1817
const cwd = process.cwd();
1918

@@ -32,22 +31,34 @@ const loaderGroup = {
3231
'style-loader': 'CSS',
3332
'stylus-loader': 'CSS',
3433
};
34+
const communityPackages = [{
35+
name: 'svg-chunk-webpack-plugin',
36+
contributors: ['yoriiis', 'alexander-akait']
37+
}];
3538

3639
async function main() {
3740
for (const type of types) {
3841
const outputDir = pathMap[type];
3942

4043
await mkdirp(outputDir);
4144

45+
/** @type string[] */
4246
const repos = JSON.parse(
4347
await readFile(path.resolve(__dirname, `../../repositories/${type}.json`))
4448
);
4549

4650
for (const repo of repos) {
47-
const [, packageName] = repo.split('/');
48-
const url = `https://raw.githubusercontent.com/${repo}/master/README.md`;
51+
const [owner, packageName] = repo.split('/');
52+
53+
const response = await api.repos.get({
54+
owner,
55+
repo: packageName,
56+
});
57+
58+
const defaultBranch = response.data.default_branch;
59+
const url = `https://raw.githubusercontent.com/${repo}/${defaultBranch}/README.md`;
4960
const htmlUrl = `https://github.com/${repo}`;
50-
const editUrl = `${htmlUrl}/edit/master/README.md`;
61+
const editUrl = `${htmlUrl}/edit/${defaultBranch}/README.md`;
5162
const fileName = path.resolve(outputDir, `_${packageName}.mdx`);
5263

5364
let title = packageName;
@@ -62,21 +73,29 @@ async function main() {
6273
let headmatter;
6374

6475
if (type === 'plugins') {
76+
let group = 'webpack contrib';
77+
let contributors = [];
78+
const packageFromCommunity = communityPackages.find((item) => item.name === packageName);
79+
if (packageFromCommunity) {
80+
group = 'Community';
81+
contributors = packageFromCommunity.contributors;
82+
}
6583
headmatter = yamlHeadmatter({
6684
title: title,
67-
group: 'webpack contrib',
85+
group,
86+
contributors,
6887
source: url,
6988
edit: editUrl,
7089
repo: htmlUrl,
71-
thirdParty: true
90+
thirdParty: true,
7291
});
7392
} else {
7493
let basic = {
7594
title: title,
7695
source: url,
7796
edit: editUrl,
7897
repo: htmlUrl,
79-
thirdParty: true
98+
thirdParty: true,
8099
};
81100

82101
if (loaderGroup[packageName]) {
@@ -85,12 +104,16 @@ async function main() {
85104
headmatter = yamlHeadmatter(basic);
86105
}
87106

88-
const response = await fetch(url);
89-
const content = await response.text();
107+
const { data: content } = await api.repos.getReadme({
108+
owner,
109+
repo: packageName,
110+
mediaType: {
111+
format: 'raw',
112+
},
113+
});
90114
const body = processReadme(content, { source: url });
91115
await writeFile(fileName, headmatter + body);
92-
await rename(fileName, mdxFileName);
93-
console.log('Generated:', path.relative(cwd, mdxFileName));
116+
console.log('Generated:', path.relative(cwd, fileName));
94117
}
95118
}
96119
}

0 commit comments

Comments
 (0)