Skip to content
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

docs(en): merge webpack.js.org/master into webpack.js.org/cn @ c9cfd74a #1475

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
bb06b28
build(deps-dev): bump jest from 27.5.0 to 27.5.1 (#5951)
dependabot[bot] Feb 8, 2022
409f7d0
fix issue#5945 (#5947)
chenxsan Feb 10, 2022
5be2b45
build(deps-dev): bump tailwindcss from 3.0.18 to 3.0.19 (#5952)
dependabot[bot] Feb 10, 2022
6940749
fix svg color for dark mode (#5957)
chenxsan Feb 11, 2022
944426a
build(deps-dev): bump @babel/core from 7.17.0 to 7.17.2 (#5953)
dependabot[bot] Feb 11, 2022
971d459
build(deps-dev): bump directory-tree from 3.1.0 to 3.2.0 (#5954)
dependabot[bot] Feb 11, 2022
423972e
build(deps-dev): bump tailwindcss from 3.0.19 to 3.0.22 (#5961)
dependabot[bot] Feb 12, 2022
1c11888
build(deps-dev): bump directory-tree from 3.2.0 to 3.2.1 (#5962)
dependabot[bot] Feb 12, 2022
aca0615
build(deps): bump follow-redirects from 1.14.7 to 1.14.8 (#5963)
dependabot[bot] Feb 12, 2022
f0353c6
build(deps-dev): bump markdownlint-cli from 0.31.0 to 0.31.1 (#5955)
dependabot[bot] Feb 13, 2022
6a74a3c
docs(api): update description for `WEBPACK_SERVE` env variable (#5965)
snitin315 Feb 13, 2022
a345efa
build(deps-dev): bump eslint from 8.8.0 to 8.9.0 (#5967)
dependabot[bot] Feb 15, 2022
9cd1fb0
docs(configuration): add note for resource name when filename is data…
snitin315 Feb 16, 2022
05fd0bc
build(deps-dev): bump lint-staged from 12.3.3 to 12.3.4 (#5968)
dependabot[bot] Feb 16, 2022
071299e
build(deps-dev): bump webpack from 5.68.0 to 5.69.0 (#5972)
dependabot[bot] Feb 16, 2022
721a919
build(deps-dev): bump cypress from 9.4.1 to 9.5.0 (#5974)
dependabot[bot] Feb 16, 2022
b043cd3
build(deps-dev): bump @babel/core from 7.17.2 to 7.17.3 (#5971)
dependabot[bot] Feb 16, 2022
cbb2393
docs(guides): clarify some caveats about dynamic import manual preloa…
artem-malko Feb 16, 2022
b081da6
build(deps): bump react-spring from 9.4.2 to 9.4.3 (#5969)
dependabot[bot] Feb 17, 2022
e9d15c5
build(deps-dev): bump sass-loader from 12.4.0 to 12.6.0 (#5973)
dependabot[bot] Feb 17, 2022
627c260
build(deps-dev): bump @babel/core from 7.17.3 to 7.17.4 (#5976)
dependabot[bot] Feb 17, 2022
805d6eb
build(deps-dev): bump webpack from 5.69.0 to 5.69.1 (#5980)
dependabot[bot] Feb 18, 2022
636d199
build(deps-dev): bump tailwindcss from 3.0.22 to 3.0.23 (#5978)
dependabot[bot] Feb 18, 2022
af70cb9
build(deps-dev): bump sass from 1.49.7 to 1.49.8 (#5981)
dependabot[bot] Feb 20, 2022
d21cfcf
build(deps-dev): bump @babel/core from 7.17.4 to 7.17.5 (#5979)
dependabot[bot] Feb 20, 2022
c9cfd74
build(deps): bump react-helmet-async from 1.2.2 to 1.2.3 (#5977)
dependabot[bot] Feb 20, 2022
2375591
docs(en): merging all conflicts
docschina-bot Feb 20, 2022
610667b
docs(en): fix conflicts
jacob-lcs Feb 23, 2022
e7c0f63
docs(en): fix conflicts
jacob-lcs Feb 23, 2022
42d9952
feat: headings have huge content areas
jacob-lcs Feb 24, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
]
},
"devDependencies": {
"@babel/core": "^7.17.0",
"@babel/core": "^7.17.5",
"@babel/eslint-parser": "^7.17.0",
"@babel/plugin-proposal-class-properties": "^7.16.7",
"@babel/preset-env": "^7.16.11",
Expand All @@ -88,29 +88,29 @@
"copy-webpack-plugin": "^10.2.4",
"css-loader": "^6.6.0",
"css-minimizer-webpack-plugin": "^3.4.1",
"cypress": "^9.4.1",
"directory-tree": "^3.1.0",
"cypress": "^9.5.0",
"directory-tree": "^3.2.1",
"directory-tree-webpack-plugin": "^1.0.3",
"duplexer": "^0.1.1",
"eslint": "^8.8.0",
"eslint": "^8.9.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-cypress": "^2.12.1",
"eslint-plugin-mdx": "^1.16.0",
"eslint-plugin-react": "^7.28.0",
"eslint-plugin-react-hooks": "^4.3.0",
"front-matter": "^4.0.2",
"github-slugger": "^1.3.0",
"github-slugger": "^1.4.0",
"html-loader": "^2.1.2",
"html-webpack-plugin": "^5.5.0",
"http-server": "^14.1.0",
"husky": "^7.0.4",
"hyperlink": "^5.0.4",
"jest": "^27.5.0",
"lint-staged": "^12.3.3",
"jest": "^27.5.1",
"lint-staged": "^12.3.4",
"lodash": "^4.17.21",
"markdownlint": "^0.25.1",
"markdownlint-cli": "^0.31.0",
"mdast-util-to-string": "^1.1.0",
"markdownlint-cli": "^0.31.1",
"mdast-util-to-string": "^3.1.0",
"mini-css-extract-plugin": "^2.5.3",
"mkdirp": "^1.0.4",
"modularscale-sass": "^3.0.3",
Expand All @@ -129,21 +129,20 @@
"remark-gfm": "^1.0.0",
"remark-html": "^15.0.1",
"remark-refractor": "montogeek/remark-refractor",
"remark-slug": "^7.0.1",
"rimraf": "^3.0.2",
"sass": "^1.49.7",
"sass-loader": "^12.4.0",
"sass": "^1.49.8",
"sass-loader": "^12.6.0",
"sirv-cli": "^2.0.2",
"sitemap-static": "^0.4.2",
"start-server-and-test": "^1.14.0",
"static-site-generator-webpack-plugin": "^3.4.1",
"style-loader": "^3.3.1",
"tailwindcss": "^3.0.18",
"tailwindcss": "^3.0.23",
"tap-spot": "^1.1.1",
"textlint": "^11.8.2",
"textlint-rule-heading": "^1.0.10",
"unist-util-visit": "^4.1.0",
"webpack": "^5.68.0",
"webpack": "^5.69.1",
"webpack-bundle-analyzer": "^4.5.0",
"webpack-cli": "^4.9.2",
"webpack-dev-server": "^4.7.4",
Expand All @@ -156,9 +155,9 @@
"prop-types": "^15.8.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-helmet-async": "^1.2.2",
"react-helmet-async": "^1.2.3",
"react-router-dom": "^6.2.1",
"react-spring": "^9.4.2",
"react-spring": "^9.4.3",
"react-tiny-popover": "5",
"react-use": "^17.3.2",
"react-visibility-sensor": "^5.0.2",
Expand Down
11 changes: 6 additions & 5 deletions src/components/Markdown/Markdown.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@use "sass:color";
@use 'sass:color';
@import 'vars';
@import 'functions';
@import 'prism-theme';
Expand Down Expand Up @@ -41,15 +41,16 @@ $topHeightMobileWithBanner: $bannerHeight + $topHeightMobile;
h4,
h5,
h6 {
&:before {
content: '';
> span[id] {
position: absolute;
width: 0;
display: block;
visibility: hidden;
pointer-events: none;
height: $topHeightMobile;
padding-top: $topHeightMobile;
margin-top: -#{$topHeightMobile};
@include break {
height: $topHeightDesktop;
padding-top: $topHeightDesktop;
margin-top: -#{$topHeightDesktop};
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/content/api/cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ T> 请查阅 [environment 变量指南](/guides/environment-variables/)了解更

| 变量名 | 描述 |
| --------------- | --------------------------------------------- |
| `WEBPACK_SERVE` | 如果使用了 `serve\|s`,则为 `true`。 |
| `WEBPACK_SERVE` | 如果使用了 `serve\|server\|s`,则为 `true`。 |
| `WEBPACK_BUILD` | 如果使用了 `build\|bundle\|b`,则为 `true`。 |
| `WEBPACK_WATCH` | 如果使用了 `--watch\|watch\|w`,则为 `true`。 |

Expand Down
2 changes: 2 additions & 0 deletions src/content/configuration/output.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ translators:

与 [`output.filename`](#outputfilename) 相同,不过应用于 [Asset Modules](/guides/asset-modules/)。

`[name]`、`[file]`、`[query]`、`[fragment]`、`[base]` 与 `[path]` 设置为空字符串,用于从数据 URI 替换构建的静态资源。

## output.asyncChunks $#outputasyncchunks$

`boolean = true`
Expand Down
25 changes: 25 additions & 0 deletions src/content/guides/code-splitting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ contributors:
- Adarah
- atesgoral
- snitin315
- artem-malko
translators:
- QC-L
- jacob-lcs
Expand Down Expand Up @@ -429,6 +430,30 @@ import(/* webpackPreload: true */ 'ChartingLibrary');

T> 不正确地使用 `webpackPreload` 会有损性能,请谨慎使用。

有时你需要自己控制预加载。例如,动态引入的预加载可以通过异步脚本(async script)完成。这对于流式服务端渲染比较有用。

```js
const lazyComp = () =>
import('DynamicComponent').catch((error) => {
// 错误处理。
// 例如,我们可以在网络错误的情况下重发请求。
});
```

如果在 webpack 自己开始加载该脚本之前脚本加载将失败(如果该脚本不在页面上,webpack 只是创建一个 script 标签来加载其代码),则该 catch 处理程序将不会启动,直到 [chunkLoadTimeout](/configuration/output/#outputchunkloadtimeout) 未通过。此行为可能是意料之外的。但这是可以解释的——webpack 不能抛出任何错误,因为 webpack 不知道那个脚本失败了。Webpack 将在错误发生后立即将 onerror 处理程序添加到 script 中。

为了防止这样的问题,你可以加载自己的 onerror 处理程序,在出现任何错误的情况下删除脚本。

```html
<script
src="https://example.com/dist/dynamicComponent.js"
async
onerror="this.remove()"
></script>
```

在这种情况下,错误的脚本将被删除。Webpack 将创建自己的脚本,并且任何错误都将被处理而没有任何延时。

## bundle 分析(bundle analysis) $#bundle-analysis$

一旦开始分离代码,一件很有帮助的事情是,分析输出结果来检查模块在何处结束。 [官方分析工具](https://github.com/webpack/analyse) 是一个不错的开始。还有一些其他社区支持的可选项:
Expand Down
22 changes: 21 additions & 1 deletion src/remark-plugins/docschina-remark-slugger/index.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import toString from 'mdast-util-to-string';
import { toString } from 'mdast-util-to-string';
import { visit } from 'unist-util-visit';
import slugs from 'github-slugger';

Expand Down Expand Up @@ -30,6 +30,26 @@ function transformer(ast) {
}
data.id = id;
props.id = id;

// insert <span id="..." /> for headings
node.children = [
{
type: 'paragraph',
data: {
hName: 'span',
hProperties: {
id,
},
},
children: [
{
type: 'text',
value: '',
},
],
},
...node.children,
];
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`customize blockquote should add id 1`] = `
"<h2><span id=\\"user-content-hello-world\\"></span>hello world</h2>
<p>this is me.</p>
"
`;
14 changes: 14 additions & 0 deletions src/remark-plugins/remark-remove-heading-id/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { visit } from 'unist-util-visit';
export default function () {
return function transformer(ast) {
visit(ast, 'heading', visitor);
};
function visitor(node) {
if (node.data && node.data.id) {
delete node.data.id;
}
if (node.data && node.data.hProperties && node.data.hProperties.id) {
delete node.data.hProperties.id;
}
}
}
23 changes: 23 additions & 0 deletions src/remark-plugins/remark-remove-heading-id/index.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { remark } from 'remark';
import remarkHtml from 'remark-html';
import Plugin from './index.mjs';
import remarkSlug from '../remark-slug/index.mjs';
describe('customize blockquote', () => {
it('should add id', () => {
remark()
.use(remarkSlug)
.use(Plugin)
.use(remarkHtml)
.process(
`
## hello world

this is me.
`,
function (err, { value: contents }) {
expect(err).toBeNull();
expect(contents).toMatchSnapshot();
}
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`remark slug should add id 1`] = `
"<h2 id=\\"user-content-hello-world\\"><span id=\\"user-content-hello-world\\"></span>hello world</h2>
<p>this is me.</p>
"
`;
56 changes: 56 additions & 0 deletions src/remark-plugins/remark-slug/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// based on https://github.com/remarkjs/remark-slug/blob/8e6394c3dd6232cc9f0fb0b05e7eaf33063effa5/index.js
// to fix https://github.com/webpack/webpack.js.org/pull/5947
/**
* @typedef {import('mdast').Root} Root
* @typedef {import('hast').Properties} Properties
*/

import { toString } from 'mdast-util-to-string';
import { visit } from 'unist-util-visit';
import BananaSlug from 'github-slugger';

const slugs = new BananaSlug();

/**
* Plugin to add anchors headings using GitHub’s algorithm.
*
* @type {import('unified').Plugin<void[], Root>}
*/
export default function remarkSlug() {
return (tree) => {
slugs.reset();

visit(tree, 'heading', (node) => {
const data = node.data || (node.data = {});
const props = /** @type {Properties} */ (
data.hProperties || (data.hProperties = {})
);
let id = props.id;

id = id ? slugs.slug(String(id), true) : slugs.slug(toString(node));

data.id = id;
props.id = id;

// insert <span id="..." /> for headings
node.children = [
{
type: 'paragraph',
data: {
hName: 'span',
hProperties: {
id,
},
},
children: [
{
type: 'text',
value: '',
},
],
},
...node.children,
];
});
};
}
20 changes: 20 additions & 0 deletions src/remark-plugins/remark-slug/index.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { remark } from 'remark';
import remarkHtml from 'remark-html';
import Plugin from './index.mjs';
describe('remark slug', () => {
it('should add id', () => {
remark()
.use(Plugin)
.use(remarkHtml)
.process(
`## hello world

this is me.
`,
function (err, { value: contents }) {
expect(err).toBeNull();
expect(contents).toMatchSnapshot();
}
);
});
});
22 changes: 22 additions & 0 deletions src/remark-plugins/remark-slug/license
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(The MIT License)

Copyright (c) 2015 Titus Wormer <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2 changes: 1 addition & 1 deletion src/styles/icons/hamburger.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion src/utilities/content-tree-enhancers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import fs from 'fs';
import path from 'path';
import frontMatter from 'front-matter';
import {remark} from 'remark';
import slug from 'remark-slug';
import slug from '../../src/remark-plugins/remark-slug/index.mjs';
import extractAnchors from 'remark-extract-anchors';
import remarkHtml from 'remark-html';
import frontmatter from 'remark-frontmatter';
import gfm from 'remark-gfm';
import emoji from 'remark-emoji';
import remarkRemoveHeadingId from '../remark-plugins/remark-remove-heading-id/index.mjs';

export const enhance = (tree, options) => {
// delete `./` root directory on node
Expand Down Expand Up @@ -46,6 +47,7 @@ export const enhance = (tree, options) => {
.use(gfm)
.use(emoji)
.use(extractAnchors, { anchors, levels: 3 })
.use(remarkRemoveHeadingId)
.use(remarkHtml)
.process(content, (err) => {
if (err) {
Expand Down
Loading