Skip to content

Commit 190c769

Browse files
authored
Merge pull request #1599 from docschina/sync-02fb7bd1
docs(en): merge webpack.js.org/master into webpack.js.org/cn @ 02fb7bd
2 parents 3eac936 + cd94694 commit 190c769

File tree

6 files changed

+628
-347
lines changed

6 files changed

+628
-347
lines changed

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@
8989
"copy-webpack-plugin": "^11.0.0",
9090
"css-loader": "^6.7.1",
9191
"css-minimizer-webpack-plugin": "^4.0.0",
92-
"cypress": "^10.1.0",
92+
"cypress": "^10.2.0",
9393
"directory-tree": "^3.3.0",
9494
"directory-tree-webpack-plugin": "^1.0.3",
9595
"duplexer": "^0.1.1",
96-
"eslint": "^8.17.0",
96+
"eslint": "^8.18.0",
9797
"eslint-config-prettier": "^8.5.0",
9898
"eslint-plugin-cypress": "^2.12.1",
99-
"eslint-plugin-mdx": "^1.17.0",
99+
"eslint-plugin-mdx": "^2.0.0",
100100
"eslint-plugin-react": "^7.30.0",
101101
"eslint-plugin-react-hooks": "^4.6.0",
102102
"front-matter": "^4.0.2",
@@ -109,7 +109,7 @@
109109
"jest": "^28.1.1",
110110
"lint-staged": "^13.0.2",
111111
"lodash": "^4.17.21",
112-
"markdownlint": "^0.25.1",
112+
"markdownlint": "^0.26.0",
113113
"markdownlint-cli": "^0.31.1",
114114
"mdast-util-to-string": "^3.1.0",
115115
"mini-css-extract-plugin": "^2.6.1",
@@ -131,13 +131,13 @@
131131
"remark-html": "^15.0.1",
132132
"remark-refractor": "montogeek/remark-refractor",
133133
"rimraf": "^3.0.2",
134-
"sass": "^1.52.3",
134+
"sass": "^1.53.0",
135135
"sass-loader": "^13.0.0",
136136
"sirv-cli": "^2.0.2",
137137
"sitemap-static": "^0.4.2",
138138
"static-site-generator-webpack-plugin": "^3.4.1",
139139
"style-loader": "^3.3.1",
140-
"tailwindcss": "^3.1.3",
140+
"tailwindcss": "^3.1.4",
141141
"tap-spot": "^1.1.2",
142142
"textlint": "^11.8.2",
143143
"textlint-rule-heading": "^1.0.10",

src/components/Page/Page.jsx

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,38 @@ export default function Page(props) {
5050
const { hash, pathname } = useLocation();
5151

5252
useEffect(() => {
53+
let observer;
5354
if (contentLoaded) {
5455
if (hash) {
55-
const element = document.querySelector(hash);
56-
if (element) {
57-
element.scrollIntoView();
56+
const target = document.querySelector('#md-content');
57+
// two cases here
58+
// 1. server side rendered page, so hash target is already there
59+
if (document.querySelector(hash)) {
60+
document.querySelector(hash).scrollIntoView();
61+
} else {
62+
// 2. dynamic loaded content
63+
// we need to observe the dom change to tell if hash exists
64+
observer = new MutationObserver(() => {
65+
const element = document.querySelector(hash);
66+
if (element) {
67+
element.scrollIntoView();
68+
}
69+
});
70+
observer.observe(target, {
71+
childList: true,
72+
attributes: false,
73+
subtree: false,
74+
});
5875
}
5976
} else {
6077
window.scrollTo(0, 0);
6178
}
6279
}
80+
return () => {
81+
if (observer) {
82+
observer.disconnect();
83+
}
84+
};
6385
}, [contentLoaded, pathname, hash]);
6486

6587
const numberOfContributors = contributors.length;
@@ -106,7 +128,7 @@ export default function Page(props) {
106128
</div>
107129
) : null}
108130

109-
{contentRender}
131+
<div id="md-content">{contentRender}</div>
110132

111133
{loadRelated && (
112134
<div className="print:hidden">

src/components/Site/Site.jsx

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ function Site(props) {
297297
<Route path="app-shell" element={<Fragment />} />
298298
{pages.map((page) => {
299299
let path = page.path.replace('src/content/', '');
300-
let content = props.import(path);
301300
const { previous, next } = getAdjacentPages(
302301
sidebarPages,
303302
page,
@@ -308,20 +307,15 @@ function Site(props) {
308307
key={page.url}
309308
path={page.url}
310309
element={
311-
<Fragment>
312-
<Sponsors />
313-
<Sidebar
314-
className="site__sidebar"
315-
currentPage={location.pathname}
316-
pages={sidebarPages}
317-
/>
318-
<Page
319-
{...page}
320-
content={content}
321-
previous={previous}
322-
next={next}
323-
/>
324-
</Fragment>
310+
<PageElement
311+
currentPage={location.pathname}
312+
sidebarPages={sidebarPages}
313+
page={page}
314+
next={next}
315+
previous={previous}
316+
import={props.import}
317+
path={path}
318+
/>
325319
}
326320
/>
327321
);
@@ -336,3 +330,27 @@ function Site(props) {
336330
);
337331
}
338332
export default Site;
333+
PageElement.propTypes = {
334+
currentPage: PropTypes.string,
335+
sidebarPages: PropTypes.array,
336+
previous: PropTypes.object,
337+
next: PropTypes.object,
338+
page: PropTypes.object,
339+
import: PropTypes.func,
340+
path: PropTypes.string,
341+
};
342+
function PageElement(props) {
343+
const { currentPage, sidebarPages, page, previous, next } = props;
344+
const content = props.import(props.path);
345+
return (
346+
<Fragment>
347+
<Sponsors />
348+
<Sidebar
349+
className="site__sidebar"
350+
currentPage={currentPage}
351+
pages={sidebarPages}
352+
/>
353+
<Page {...page} content={content} previous={previous} next={next} />
354+
</Fragment>
355+
);
356+
}

src/content/guides/csp.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ related:
2222
url: https://web.dev/trusted-types
2323
---
2424

25-
Webpack 能够为其加载的所有脚本添加 `nonce`。要启用此功能,需要在引入的入口脚本中设置一个 `__webpack_nonce__` 变量。应该为每个唯一的页面视图生成和提供一个唯一的基于 hash 的 nonce,这就是为什么 `__webpack_nonce__` 要在入口文件中指定,而不是在配置中指定的原因。注意,`nonce` 应该是一个 base64 编码的字符串。
25+
Webpack 能够为其加载的所有脚本添加 `nonce`。要启用此功能,需要在引入的入口脚本中设置一个 `__webpack_nonce__` 变量。应该为每个唯一的页面视图生成和提供一个唯一的基于 hash 的 `nonce`,这就是为什么 `__webpack_nonce__` 要在入口文件中指定,而不是在配置中指定的原因。注意,`__webpack_nonce__` 应该是一个 base64 编码的字符串。
2626

2727
## 示例 $#examples$
2828

src/content/guides/ecma-script-modules.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Node.js 通过设置 `package.json` 中的属性来显式设置文件模块类
8282

8383
除了模块格式外,将模块标记为 ESM 还会影响解析逻辑,操作逻辑和模块中的可用符号。
8484

85-
导入模块在 ESM 中更为严格,导入相对路径的模块必须包含文件名和文件扩展名。
85+
导入模块在 ESM 中更为严格,导入相对路径的模块必须包含文件名和文件扩展名(例如 `*.js` 或者 `*.mjs`),除非你设置了 [`fullySpecified=false`](/configuration/module/#resolvefullyspecified)
8686

8787
T> 依旧支持导入包,例如 `import "lodash"` .
8888

0 commit comments

Comments
 (0)