diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index b489f0e6e61f..000000000000 --- a/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ -- [ ] Check the current issues to ensure you aren't creating a duplicate. -- [ ] Consider making small typo fixes and such directly as pull requests. -- [ ] For the voting application, go to https://github.com/webpack-contrib/voting-app. -- [ ] For the document of Chinese translation(中文版文档), go to https://github.com/docschina/webpack.js.org. -- [ ] For loader/plugin docs, consider opening an issue in the corresponding repository. -- [ ] No existing issue? Go ahead and open a new one. -- **Remove these instructions from your PR as they are for your eyes only.** diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index fb181665c983..000000000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,11 +0,0 @@ -_describe your changes..._ - -- [ ] Read and sign the [CLA][1]. PRs that haven't signed it won't be accepted. -- [ ] Make sure your PR complies with the [writer's guide][2]. -- [ ] Review the diff carefully as sometimes this can reveal issues. -- [ ] Do not abandon your Pull Request: [Stale Pull Requests][3]. -- **Remove these instructions from your PR as they are for your eyes only.** - -[1]: https://github.com/openjs-foundation/EasyCLA#openjs-foundation-cla -[2]: https://webpack.js.org/contribute/writers-guide/ -[3]: https://webpack.js.org/contribute/#pull-requests diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml new file mode 100644 index 000000000000..c473da562140 --- /dev/null +++ b/.github/workflows/build-pr.yml @@ -0,0 +1,35 @@ +# This is a basic workflow to help you get started with Actions + +name: CI PR + +# Controls when the action will run. Triggers the workflow on push or pull request +# events but only for the master branch +on: + push: + branches: [cn] + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + + - name: Install + run: | + yarn + yarn clean + + - name: Build + run: | + yarn build + + - name: Check Build + run: | + sudo -i + sudo chown -R $USER ./dist diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index 747b1fb03681..a25de591ba3c 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -1,14 +1,14 @@ -# name: 'Dependency Review' -# on: [pull_request] +name: 'Dependency Review' +on: [pull_request] -# permissions: -# contents: read +permissions: + contents: read -# jobs: -# dependency-review: -# runs-on: ubuntu-latest -# steps: -# - name: 'Checkout Repository' -# uses: actions/checkout@v4 -# - name: 'Dependency Review' -# uses: actions/dependency-review-action@v3 +jobs: + dependency-review: + runs-on: ubuntu-latest + steps: + - name: 'Checkout Repository' + uses: actions/checkout@v3 + - name: 'Dependency Review' + uses: actions/dependency-review-action@v2 diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index d6abae836fb5..c254eb5e33d0 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,9 +1,11 @@ +# The file need not be maintained in the cn repo. + name: Deploy on: push: branches: - - main + - master schedule: - cron: '0 0 * * *' jobs: @@ -12,10 +14,10 @@ jobs: strategy: matrix: os: [ubuntu-latest] - node-version: [latest] + node-version: [16.x] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v3 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v3 @@ -41,7 +43,7 @@ jobs: - run: yarn lint:links - name: Deploy - uses: JamesIves/github-pages-deploy-action@v4.4.3 + uses: JamesIves/github-pages-deploy-action@v4.4.0 with: token: ${{ secrets.GITHUB_TOKEN }} folder: dist diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d5289e4ff56a..7e5b6a6d6bff 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,4 +1,4 @@ -# This is a basic workflow to help you get started with Actions +# This file should modified carefully. name: CI @@ -18,7 +18,7 @@ jobs: # Steps represent a sequence of tasks that will be executed as part of the job steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v4 + - uses: actions/checkout@v2 - name: Install run: | diff --git a/package.json b/package.json index 7556bd2d6471..debde1002f4b 100644 --- a/package.json +++ b/package.json @@ -28,15 +28,15 @@ "clean-printable": "rimraf src/content/**/printable.mdx", "preclean": "run-s clean-dist clean-printable", "clean": "rimraf src/content/**/_*.mdx src/**/_*.json repositories/*.json", - "start": "npm run clean-dist && webpack serve --config webpack.dev.mjs --env dev --progress --define-process-env-node-env development", + "start": "npm run clean-dist && webpack serve --config webpack.dev.mjs --env dev --progress --node-env development", "content": "node src/scripts/build-content-tree.mjs ./src/content ./src/_content.json", - "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", + "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", "fetch-repos": "node src/utilities/fetch-package-repos.mjs", "fetch": "run-p fetch:*", "fetch:readmes": "node src/utilities/fetch-package-readmes.mjs", "fetch:supporters": "node src/utilities/fetch-supporters.mjs", "prebuild": "npm run clean", - "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", + "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", "postbuild": "npm run sitemap", "build-test": "npm run build && http-server --port 4200 dist/", "serve-dist": "http-server --port 4200 dist/", @@ -48,6 +48,9 @@ "lint-markdown": "markdownlint --config ./.markdownlint.json", "lint:prose": "vale --config='.vale.ini' src/content", "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", + "lint:heading": "textlint --fix src/content/*", + "lint:heading-blog": "textlint --fix src/content/blog/*", + "lint:headingMDX": "textlint --fix src/content/**/*.mdx", "sitemap": "cd dist && sitemap-static --ignore-file=../sitemap-ignore.json --pretty --prefix=https://webpack.js.org/ > sitemap.xml", "serve": "npm run build && sirv start ./dist --port 4000", "preprintable": "npm run clean-printable", @@ -70,97 +73,102 @@ ] }, "devDependencies": { - "@babel/core": "^7.22.19", - "@babel/eslint-parser": "^7.22.15", + "@babel/core": "^7.19.6", + "@babel/eslint-parser": "^7.19.1", "@babel/plugin-proposal-class-properties": "^7.17.12", - "@babel/preset-env": "^7.22.15", - "@babel/preset-react": "^7.22.15", + "@babel/preset-env": "^7.19.4", + "@babel/preset-react": "^7.18.6", "@mdx-js/loader": "^2.0.0-next.9", - "@octokit/auth-action": "^4.0.0", - "@octokit/rest": "^20.0.1", + "@octokit/auth-action": "^2.0.2", + "@octokit/rest": "^19.0.5", "@pmmmwh/react-refresh-webpack-plugin": "next", - "@svgr/webpack": "^8.1.0", - "autoprefixer": "^10.4.15", - "babel-loader": "^9.1.3", + "@svgr/webpack": "^6.5.1", + "autoprefixer": "^10.4.13", + "babel-loader": "^9.0.0", "copy-webpack-plugin": "^11.0.0", - "css-loader": "^6.8.1", - "css-minimizer-webpack-plugin": "^5.0.1", - "cypress": "^13.2.0", - "directory-tree": "^3.5.1", + "css-loader": "^6.7.1", + "css-minimizer-webpack-plugin": "^4.2.2", + "cypress": "^10.11.0", + "directory-tree": "^3.3.1", "directory-tree-webpack-plugin": "^1.0.3", "duplexer": "^0.1.1", - "eslint": "^8.49.0", - "eslint-config-prettier": "^9.0.0", - "eslint-plugin-cypress": "^2.14.0", - "eslint-plugin-mdx": "^2.2.0", - "eslint-plugin-react": "^7.33.2", + "eslint": "^8.26.0", + "eslint-config-prettier": "^8.5.0", + "eslint-plugin-cypress": "^2.12.1", + "eslint-plugin-mdx": "^2.0.5", + "eslint-plugin-react": "^7.31.10", "eslint-plugin-react-hooks": "^4.6.0", "front-matter": "^4.0.2", "github-slugger": "^2.0.0", - "html-webpack-plugin": "^5.5.3", + "html-loader": "^2.1.2", + "html-webpack-plugin": "^5.5.0", "http-server": "^14.1.1", - "husky": "^8.0.3", + "husky": "^8.0.1", "hyperlink": "^5.0.4", "jest": "^29.7.0", - "lightningcss": "^1.21.8", - "lint-staged": "^14.0.1", + "lightningcss": "^1.16.0", + "lint-staged": "^13.0.3", "lodash": "^4.17.21", - "markdownlint-cli": "^0.36.0", - "mdast-util-to-string": "^4.0.0", - "mini-css-extract-plugin": "^2.7.6", - "mkdirp": "^3.0.1", + "markdownlint": "^0.26.2", + "markdownlint-cli": "^0.32.2", + "mdast-util-to-string": "^3.1.0", + "mini-css-extract-plugin": "^2.6.1", + "mkdirp": "^1.0.4", "modularscale-sass": "^3.0.3", + "node-fetch": "^3.2.10", "npm-run-all": "^4.1.1", - "postcss": "^8.4.29", - "postcss-loader": "^7.3.3", - "prettier": "^3.0.3", + "postcss": "^8.4.18", + "postcss-loader": "^7.0.1", + "prettier": "^2.7.1", "react-refresh": "^0.14.0", "redirect-webpack-plugin": "^1.0.0", - "remark": "^14.0.3", + "remark": "^14.0.2", "remark-autolink-headings": "7.0.1", - "remark-emoji": "^4.0.0", + "remark-emoji": "^3.0.2", "remark-extract-anchors": "1.1.1", "remark-frontmatter": "^4.0.1", "remark-gfm": "^1.0.0", - "remark-html": "^15.0.2", + "remark-html": "^15.0.1", "remark-refractor": "montogeek/remark-refractor", - "rimraf": "^5.0.1", - "sass": "^1.67.0", - "sass-loader": "^13.3.2", + "rimraf": "^3.0.2", + "sass": "^1.55.0", + "sass-loader": "^13.1.0", "sirv-cli": "^2.0.2", "sitemap-static": "^0.4.2", "static-site-generator-webpack-plugin": "^3.4.1", - "style-loader": "^3.3.3", - "tailwindcss": "^3.3.3", + "style-loader": "^3.3.1", + "tailwindcss": "^3.2.1", "tap-spot": "^1.1.2", - "unist-util-visit": "^5.0.0", - "webpack": "^5.88.2", - "webpack-bundle-analyzer": "^4.9.1", - "webpack-cli": "^5.1.4", - "webpack-dev-server": "^4.15.1", - "webpack-merge": "^5.9.0", - "workbox-webpack-plugin": "^7.0.0", - "yarn-deduplicate": "^6.0.2" + "textlint": "^11.8.2", + "textlint-rule-heading": "^1.0.10", + "unist-util-visit": "^4.1.1", + "webpack": "^5.74.0", + "webpack-bundle-analyzer": "^4.7.0", + "webpack-cli": "^4.10.0", + "webpack-dev-server": "^4.11.1", + "webpack-merge": "^5.8.0", + "workbox-webpack-plugin": "^6.5.4", + "yarn-deduplicate": "^6.0.0" }, "dependencies": { "@docsearch/react": "^3.0.0-alpha.50", - "@react-spring/web": "^9.7.3", "path-browserify": "^1.0.1", "prop-types": "^15.8.1", "react": "^17.0.2", "react-dom": "^17.0.2", "react-helmet-async": "^1.3.0", - "react-router-dom": "^6.16.0", + "react-router-dom": "^6.4.2", + "react-spring": "^9.5.5", "react-tiny-popover": "5", "react-use": "^17.4.0", "react-visibility-sensor": "^5.0.2", "webpack-pwa-manifest": "^4.3.0", - "workbox-window": "^7.0.0" + "webpack.vote": "https://github.com/webpack/voting-app.git", + "workbox-window": "^6.5.4" }, "resolutions": { "sitemap-static/minimist": "1.2.5", "ini": "1.3.7", - "eval": "^0.1.5", - "markdownlint-cli/markdownlint": "^0.27.0" + "eval": "^0.1.5" } } diff --git a/src/components/HelloDarkness.jsx b/src/components/HelloDarkness.jsx index 798e783e2fde..4396a11dd228 100644 --- a/src/components/HelloDarkness.jsx +++ b/src/components/HelloDarkness.jsx @@ -52,7 +52,7 @@ export default function HelloDarkness() { xmlns="http://www.w3.org/2000/svg" > @@ -65,7 +65,39 @@ export default function HelloDarkness() { xmlns="http://www.w3.org/2000/svg" > + + + + + + + + diff --git a/src/components/Markdown/prism-theme.scss b/src/components/Markdown/prism-theme.scss index 93b1c01d4a6d..92e1687ab021 100644 --- a/src/components/Markdown/prism-theme.scss +++ b/src/components/Markdown/prism-theme.scss @@ -75,7 +75,6 @@ pre[class*='lang-'] { .token.deleted { color: #f79494; - user-select: none; } .token.operator, diff --git a/src/components/NotificationBar/MessageBar.jsx b/src/components/NotificationBar/MessageBar.jsx index e2c4c6c228c6..f315f7bc23ca 100644 --- a/src/components/NotificationBar/MessageBar.jsx +++ b/src/components/NotificationBar/MessageBar.jsx @@ -2,7 +2,7 @@ import CloseIcon from '../../styles/icons/cross.svg'; import PropTypes from 'prop-types'; import Content from './Notification.mdx'; import { version, localStorageIsEnabled } from './NotificationBar'; -import { useTransition, animated, config } from 'react-spring/web'; +import { useTransition, animated, config } from 'react-spring'; import { useEffect, useState } from 'react'; MessageBar.propTypes = { diff --git a/src/components/NotifyBox/NotifyBox.js b/src/components/NotifyBox/NotifyBox.js new file mode 100644 index 000000000000..bb4714ab918d --- /dev/null +++ b/src/components/NotifyBox/NotifyBox.js @@ -0,0 +1,63 @@ +import PropTypes from 'prop-types'; +import ChevronRightIcon from '../../styles/icons/chevron-right.svg'; +import './NotifyBox.scss'; +import { animated, useSpring } from 'react-spring'; +import { useLocalStorage } from 'react-use'; +NotifyBox.propTypes = { + skip: PropTypes.func.isRequired, + loading: PropTypes.bool, +}; +const AnimatedChevron = animated(ChevronRightIcon); +export default function NotifyBox(props = { loading: false }) { + const [collapse, setCollapse] = useLocalStorage('app-update-button', false); + const toggle = () => setCollapse(!collapse); + const rotateStyles = useSpring({ + transform: collapse ? 'rotate(180deg)' : 'rotate(0deg)', + }); + const fadeStyles = useSpring({ + display: collapse ? 'none' : 'inline-flex', + opacity: collapse ? 0 : 1, + }); + return ( +
+ + + + + 检测到文档有更新 + + +
+ ); +} diff --git a/src/components/Sidebar/Sidebar.jsx b/src/components/Sidebar/Sidebar.jsx index 87d567578a4e..b48b3158dab3 100644 --- a/src/components/Sidebar/Sidebar.jsx +++ b/src/components/Sidebar/Sidebar.jsx @@ -49,7 +49,7 @@ export default function Sidebar({ className = '', pages, currentPage }) { > {versions.map((version) => ( ))} diff --git a/src/components/Sidebar/Sidebar.scss b/src/components/Sidebar/Sidebar.scss index 71e6bbc2816b..9995296371ce 100644 --- a/src/components/Sidebar/Sidebar.scss +++ b/src/components/Sidebar/Sidebar.scss @@ -17,8 +17,14 @@ padding: 1.5em; position: sticky; top: -1px; - overflow-y: auto; + overflow: scroll; max-height: 100vh; + // To hide scrollbar in Firefox + scrollbar-width: none; + // To hide scrollbar in Chrome + &::-webkit-scrollbar { + width: 0 !important; + } } .sidebar__group { diff --git a/src/components/SidebarItem/SidebarItem.jsx b/src/components/SidebarItem/SidebarItem.jsx index 8c231e8549f2..6283e22b1457 100644 --- a/src/components/SidebarItem/SidebarItem.jsx +++ b/src/components/SidebarItem/SidebarItem.jsx @@ -36,22 +36,36 @@ export default class SidebarItem extends Component { renderAnchors(anchors) { return (
    - {anchors.map((anchor) => ( -
  • - - {anchor.title2} - - {anchor.children && this.renderAnchors(anchor.children)} -
  • - ))} + {anchors.map((anchor) => { + anchor = this._handleAnchor(anchor); + return ( +
  • + + {anchor.title} + + {anchor.children && this.renderAnchors(anchor.children)} +
  • + ); + })}
); } + _handleAnchor(anchor) { + let id = anchor.id; + let title = anchor.title2; + const match = /^.+(\s*\$#([a-z0-9\-_]+?)\$\s*)$/.exec(title); + id = match ? match[2] : id; + title = match ? title.replace(match[1], '').trim() : title; + anchor.id = id; + anchor.title = title; + return anchor; + } + render() { let { title, anchors = [] } = this.props; let openMod = this.state.open ? `${block}--open` : ''; diff --git a/src/components/Site/Site.jsx b/src/components/Site/Site.jsx index ec04b349276d..e006207c13f4 100644 --- a/src/components/Site/Site.jsx +++ b/src/components/Site/Site.jsx @@ -31,6 +31,7 @@ import Sidebar from '../Sidebar/Sidebar'; import Footer from '../Footer/Footer'; import Page from '../Page/Page'; import PageNotFound from '../PageNotFound/PageNotFound'; +import Vote from '../Vote/Vote'; import Badge from '../Badge/Badge.js'; import StackBlitzPreview from '../StackBlitzPreview/StackBlitzPreview'; import { default as LinkComponent } from '../mdxComponents/Link'; @@ -241,6 +242,11 @@ function Site(props) { +
} > + } /> } /> {pages.map((page) => { let path = page.path.replace('src/content/', ''); diff --git a/src/components/Splash/Splash.jsx b/src/components/Splash/Splash.jsx index d378fb034881..402e22ebe1e9 100644 --- a/src/components/Splash/Splash.jsx +++ b/src/components/Splash/Splash.jsx @@ -1,5 +1,5 @@ // Import External Dependencies -import { useState, useEffect } from 'react'; +import { lazy, Suspense, useState, useEffect } from 'react'; // Import Components import Container from '../Container/Container'; @@ -18,7 +18,36 @@ import './Splash.scss'; // const Support = lazy(() => import('../Support/Support')); +const SponsorsPlaceholder = () => ( + <> +

Latest Sponsors

+ + +

Platinum Sponsors

+ + +

Gold Sponsors

+ + +

Silver Sponsors

+ + +

Bronze Sponsors

+ + +

Backers

+ + +); + const Splash = () => { + const [showSponsors, setShowSponsors] = useState(false); + const [supportType, setSupportType] = useState(() => + Math.random() < 0.33 ? 'monthly' : 'total' + ); + useEffect(() => { + if (isClient) setShowSponsors(true); + }, []); return (
diff --git a/src/components/Stats/StatsScript.js b/src/components/Stats/StatsScript.js index ca8bb293ef2c..0bcdaa69387a 100644 --- a/src/components/Stats/StatsScript.js +++ b/src/components/Stats/StatsScript.js @@ -1,3 +1,5 @@ +import React from 'react'; + const statsScript = ` var _hmt = _hmt || []; (function() { @@ -11,4 +13,4 @@ export default function StatsScript () { return ( ); -} +} \ No newline at end of file diff --git a/src/components/Vote/Vote.jsx b/src/components/Vote/Vote.jsx new file mode 100644 index 000000000000..d7b4929c78ea --- /dev/null +++ b/src/components/Vote/Vote.jsx @@ -0,0 +1,27 @@ +import { Component } from 'react'; +import Container from '../Container/Container'; +import 'webpack.vote/dist/style.min.css'; + +// Load Styling +import './Vote.scss'; + +export default class Vote extends Component { + state = { + VoteApp: null, + }; + componentDidMount() { + if (window && !window.__ssgrun) { + import('webpack.vote').then((VoteApp) => { + this.setState({ VoteApp: VoteApp.default || VoteApp }); + }); + } + } + render() { + const { VoteApp } = this.state; + return ( + + {VoteApp ? : null} + + ); + } +} diff --git a/src/components/Vote/Vote.scss b/src/components/Vote/Vote.scss new file mode 100644 index 000000000000..2e2d8d110ca3 --- /dev/null +++ b/src/components/Vote/Vote.scss @@ -0,0 +1,6 @@ +.vote { + ul, + ol { + padding-left: 0; + } +} diff --git a/src/content/concepts/module-federation.mdx b/src/content/concepts/module-federation.mdx index d4c996a5bba0..99b306cab7c6 100644 --- a/src/content/concepts/module-federation.mdx +++ b/src/content/concepts/module-federation.mdx @@ -93,7 +93,7 @@ packageName 选项允许通过设置包名来查找所需的版本。默认情 - 将提供所有匹配模块 - 将从图中这个位置的 package.json 提取 `requiredVersion` - 当你有嵌套的 node_modules 时,可以提供和使用多个不同的版本 -- 共享中尾部带有 `/` 的模块请求将匹配所有具有这个前缀的模块请求 +- 共享中尾部带有 `/`  的模块请求将匹配所有具有这个前缀的模块请求 ## 用例 $#use-cases$ @@ -107,7 +107,7 @@ packageName 选项允许通过设置包名来查找所需的版本。默认情 ## 动态远程容器 $#dynamic-remote-containers$ -该容器接口支持 `get` 和 `init` 方法。 +该容器接口支持 `get`  和 `init` 方法。 `init` 是一个兼容 `async` 的方法,调用时,只含有一个参数:共享作用域对象(shared scope object)。此对象在远程容器中用作共享作用域,并由 host 提供的模块填充。 可以利用它在运行时动态地将远程容器连接到 host 容器。 @@ -337,7 +337,7 @@ ReactDOM.render(, document.getElementById('root')); 这种方法有效,但存在局限性或缺点。 -通过 `ModuleFederationPlugin` 将依赖的 `eager` 属性设置为 `true` +通过 `ModuleFederationPlugin`  将依赖的 `eager` 属性设置为 `true` **webpack.config.js** diff --git a/src/content/configuration/module.mdx b/src/content/configuration/module.mdx index 7ae4325870c5..28d8d23f0d2d 100644 --- a/src/content/configuration/module.mdx +++ b/src/content/configuration/module.mdx @@ -670,12 +670,12 @@ module.exports = { node: false, // 禁用 __dirname, __filename, module, require.extensions, require.main, 等。 commonjsMagicComments: false, // 禁用对 CommonJS 的 magic comments 支持 node: {}, // 在模块级别(module level)上重新配置 node 层(layer) - worker: ['default from web-worker', '...'] // 自定义 WebWorker 对 JavaScript 的处理,其中 "..." 为默认值。 + worker: ["default from web-worker", "..."] // 自定义 WebWorker 对 JavaScript 的处理,其中 "..." 为默认值。 } } ] } -}; +} ``` 如果 `Rule.type` 的值为 `asset`,那么 `Rules.parser` 选项可能是一个对象或一个函数,其作用可能是将文件内容编码为 Base64,还可能是将其当做单独文件 emit 到输出目录。 diff --git a/src/content/configuration/plugins.mdx b/src/content/configuration/plugins.mdx index efe1f731734e..72ce2d734cbf 100644 --- a/src/content/configuration/plugins.mdx +++ b/src/content/configuration/plugins.mdx @@ -51,11 +51,11 @@ module.exports = { //... plugins: [ new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/), - // 编译时(compile time)插件 + // 编译时(compile time)插件 new webpack.DefinePlugin({ 'process.env.NODE_ENV': '"production"', }), - // webpack-dev-server 强化插件 + // webpack-dev-server 强化插件 new DashboardPlugin(), new webpack.HotModuleReplacementPlugin(), ], diff --git a/src/content/guides/asset-management.mdx b/src/content/guides/asset-management.mdx index b584221b89bd..89fda4c310e3 100644 --- a/src/content/guides/asset-management.mdx +++ b/src/content/guides/asset-management.mdx @@ -18,15 +18,15 @@ translators: - Yucohny --- -如果是从一开始就沿用指南的示例,现在应该有一个可以显示“Hello webpack”的小项目。接下来尝试混合一些图像之类的其他资源,看看 webpack 如何处理。 +如果你是从一开始就沿用指南的示例,现在应该有一个显示 “Hello webpack” 的小项目。接下来我们尝试混合一些图像之类的其他资源,看看 webpack 如何处理。 -在 webpack 出现之前,前端开发人员会使用 [grunt](https://gruntjs.com/) 和 [gulp](https://gulpjs.com/) 等工具处理资源,并将它们从 `/src` 文件夹移动到 `/dist` 或 `/build` 目录中。JavaScript 模块也遵循同样的方式。但是,像 webpack 这样的工具将 **动态打包** 所有依赖并创建所谓的 [依赖图](/concepts/dependency-graph)。这是极好的创举,因为现在每个模块都可以 **明确表述它自身的依赖**,以避免打包未使用的模块。 +在 webpack 出现之前,前端开发人员会使用 [grunt](https://gruntjs.com/) 和 [gulp](https://gulpjs.com/) 等工具来处理资源,并将它们从 `/src` 文件夹移动到 `/dist` 或 `/build` 目录中。JavaScript 模块也遵循同样的方式,但是,像 webpack 这样的工具将 **动态打包** 所有依赖(创建所谓的 [依赖图](/concepts/dependency-graph))。这是极好的创举,因为现在每个模块都可以 **明确表述它自身的依赖**,以避免打包未使用的模块。 -webpack 最出色的功能之一就是除了引入 JavaScript,还可以通过 loader 或内置的 [资源模块](/guides/asset-modules/) **引入任何其他类型的文件**。换言之,以上列出的那些 JavaScript 的优点(例如显式依赖),同样可以用来构建 web 站点或 web 应用程序中的所有非 JavaScript 内容。让我们从 CSS 开始起步,或许你可能已经熟悉了下面这些设置。 +webpack 最出色的功能之一就是除了引入 JavaScript,还可以通过 loader 或内置的 [Asset Modules](/guides/asset-modules/) **引入任何其他类型的文件**。换言之,以上列出的那些 JavaScript 的优点(例如显式依赖),同样可以用来构建 web 站点或 web 应用程序中的所有非 JavaScript 内容。让我们从 CSS 开始起步,或许你可能已经熟悉了下面这些设置。 ## 设置 $#setup$ -在开始前对项目做一个小的修改: +在开始之前,让我们对项目做一个小的修改: **dist/index.html** @@ -62,7 +62,7 @@ webpack 最出色的功能之一就是除了引入 JavaScript,还可以通过 ## 加载 CSS $#loading-css$ -要想在 JavaScript 模块中导入 CSS 文件,需要安装 [style-loader](/loaders/style-loader) 和 [css-loader](/loaders/css-loader),并在 [`module` 配置](/configuration/module) 中添加这些 loader: +要想在 JavaScript 模块中 `import` CSS 文件,需要安装 [style-loader](/loaders/style-loader) 和 [css-loader](/loaders/css-loader),并在 [`module` 配置](/configuration/module) 中添加这些 loader: ```bash npm install --save-dev style-loader css-loader @@ -96,7 +96,7 @@ module loader 可以链式调用。链中的每个 loader 都将对资源进行 T> webpack 根据正则表达式确定应该查找哪些文件,并将其提供给指定的 loader。在此示例中,所有以 `.css` 结尾的文件,都将被提供给 `style-loader` 和 `css-loader`。 -这些配置可以帮助在依赖于此样式的 JavaScript 文件中 `import './style.css'`。现在,在此模块执行过程中,含有 CSS 字符串的 `