Skip to content

Commit 6be1efe

Browse files
* update /content/loaders & /content/plugins * update /content/loaders & /content/plugins * update /content/loaders & /content/plugins * update contributors * update /content/loaders & /content/plugins * fix LinkDropdown * 修复 npm 命令错误导致编译不成功的问题 * update /content/loaders & /content/plugins * update /content/loaders & /content/plugins * update /content/loaders & /content/plugins * docs(plugins): fix typo in module-concatenation-plugin.md (#1683) * docs(concepts): simplify the introduction (#1673) Make the `index` page more beginner friendly with less technical lingo and complex details. Resolves #1416 * docs(plugins): add “scope hoisting” intro in module-concatenation-plugin (#1684) This adds a link between “concatenation behavior” and “scope hoisting”. Without this, a new person might be confused what exactly “scope hoisting” is (because it appears without any visible connection to the previous content). * docs(api): fix some method signatures in loaders.md (#1685) In actual fact the parameters passed to `emitWarning` / `emitError` must be an instance of Error. * update /content/loaders & /content/plugins * docs(guides): consistent quoute use in typescript.md (#1687) * docs(api/guides): document new --concatenate-modules flag (#1686) Document the new `--concatenate-modules` flag in both the CLI documentation and production guide. Add section on the `ModuleConcatenationPlugin` in the production guide (as we include this plugin under `-p`, it also makes sense to mention it in this guide. * docs(guides): fix issues with examples in shimming.md (#1680) Rename plugin identifier and require webpack when it is used in the configuration examples. * docs(guides): add middleware tip to the hmr guide Resolves #1682 * Revert "A new --concatenate-modules flag" (#1692) * update master * update /content/loaders & /content/plugins * docs(concepts): fix grammar in output.md (#1694) * docs(contribute): update writing-a-loader (#1691) Use normal function instead of arrow function to fix scope in loader example. * docs(plugins): add external example in SourceMapDevToolPlugin (#1676) Demonstrate how one might use the plugin to host source maps externally. * docs(config): update dev-server open option (#1693) State the ability to open in specific browser. * fix bugs * update /content/loaders & /content/plugins * docs(api): improve formatting and grammar in loaders.md * docs(api): clarify fourth parameter of `this.callback` in loaders.md Add some lead in descriptions to the `Examples` section and clarify that meta data can be passed along via the fourth parameter to `this.callback` and accepted as the third parameter to a loader function. Resolves #1607 * docs(api): populate missing link in loaders.md * docs(plugins): correct example in html-webpack-plugin (#1698) * docs(guides): update an example in production.md (#1696) Switch to shortened form when using the `DefinePlugin` to define the `process.env.NODE_ENV` value. This avoids a bug which is mentioned in the plugin's documentation: https://webpack.js.org/plugins/define-plugin/#feature-flags * fix(markdown): fix overflowing inline code (#1701) Change the css to fix the text inside code tag which was overflowing the parent div. * docs(concepts): update concepts wording (#1702) Add "static" to "module bundler". Some feedback here was given to me on twitter to make sure we are clear with what these terms mean. * update /content/loaders & /content/plugins * docs(config): fix dead link to webpack-dev-server example (#1704) * docs(concepts): use fragment links in usage instructions (#1705) This is just a quality of life adjustment that updates the list of ways to use loaders with fragment links to the relevant section in the docs. In their current state, the section feels like a dead end, abruptly cutting off with three bullet points and no examples. While one can read on and figure it out, there is a break in focus that is quite distracting. * docs(guides): add windows usage tip in getting-started (#1671) * doc(guides): fix grammatical error in build-performance (#1709) Change "less" to "fewer". * docs(guides): correct two small typos * docs(api): remove inadvertent double verb (#1714) * docs(contribute): fix grammar in writing-a-plugin (#1715) * docs(config): add semicolon for consistency (#1716) The final code block was missing a semicolon from the end of the first line; added it in to match the other require statements. * docs(contributing): add note about debian OS (#1721) Related issue: #1718 * docs(guides): add output example to shimming doc (#1720) * docs(plugins): use `.includes` over `.indexOf` (#1719) Really minor but I think `.includes` is more readable to the unfamiliar with javascript. * docs(guides): use `npx` in getting-started (#1708) Keep the mention the webpack binary's path but use the `npx` utility now that it ships with Node. Fix some punctuation and grammar. Clarify why npm scripts are still useful even over `npx`. * update /src/content/loaders & /src/content/plugins * docs(contribute): link compiler docs in writing-a-plugin (#1700) While authoring plugins the list of hooks is essential knowledge, so a link to hooks documentation page should be accessible in the top of writing a plugin guide. * docs(guides): fix `source-map` discrepancy in production.md (#1711) The `webpack.prod.js` code example in the "Specify the Evironment" section shows `cheap-module-source-map` for the `devtool` field which is not recommended for production. This section should show `source-map` to be consistent with the webpack.prod.js in the previous "Source Mapping" section. * docs(guides): rename 'runtime' to 'manifest' in caching.md (#1713) Preserve CommonsChunkPlugin boilerplate naming consistency as referenced in the CommonsChunkPlugin documentation (see below) when extracting webpack runtime and manifest boilerplate. https://webpack.js.org/plugins/commons-chunk-plugin#manifest-file * docs(guides): update output to webpack 3.9.1 (#1724) * docs(plugins): update the source-map-devtool-plugin (#1707) Clean up formatting a bit and add undocumented options from webpack/webpack#5986. Update the external source maps example to demonstrate path stripping. * docs(contribute): correct an example in the writers-guide (#1727) In a section which states the properties must be sorted alphabetically, sort the examples alphabetically. * docs(config): improve formatting and add note about library entry points in output.md * docs(guides): mention complex entry point configuration in author-libraries Note that `entry` arrays are not recommended, provide a way to properly expose stylesheets, and add a link to an `entry` object example. * docs(config): improve formatting and clarify the string usage in externals Resolves #1726 * docs(config): fix minor proselint error in externals * docs(api): clarify the `pitch` method and how it can be used in loaders.md Resolves #449 Resolves webpack#116 Refactored and enhanced the existing section using much of @sokra's explanation from: webpack/webpack#360 * docs(contribute): fix `import` statement in writing-a-loader.md (#1732) `validateOptions` is exported as a default module. * docs(config): update devtool production recommendations * docs(api): remove obsolete cli flag (#1733) The `--save` option has been removed from webpack's CLI. See the following pull request for reference: webpack/webpack#3896 * docs(concepts): add warning about incompatible `import` statements Resolves #1736 * docs(config): fix typescript setup in configuration-languages (#1734) Resolves #1735 * docs: use full `npm install` over `npm i` (#1740) Most of the guides use the full command, so it's best to stay consistent. * docs(guides): fix diff display for webpack.config.js entry object Resolves #1743 * docs: fix typos * docs: add tbroadley to contributor lists * docs(contribute): correct schema example in `writing-a-loader.md` (#1753) * docs(guides): add pwa guide (#1737) Add `progressive-web-application.md` guide which documents how to use the `workbox-webpack-plugin` to build an offline app. More on PWAs in webpack can be added here by future contributors. Resolves #1145 * docs(guides): highlight css splitting in production Resolves #1741 * docs(plugins): use `.includes` over `.indexOf` Consistent usage of `.includes` * docs(config): omit invalid `detailed` option in stats.md (#1757) * fix(mobile): correctly sort pages in mobile sidebar (#1759) * chore(vote): port voting app, update deps, and simplify config (#1717) Port the voting app to a it's own repository and expose that section of the site more prominently (in the header). This commit also... - Simplifies the webpack config slightly and allows external styles. - Updates issue template to highlight content from other repositories. - Updates some outdated dependencies. * docs(readme): reformat at 80 characters and include browserstack link By including this, _BrowserStack_ will allow us to do free testing of the site on their platform. * refactor(notification): simplify notification message and bump the version * fix(splash): fix visualization artifacts (#1762) Rebuild and clean up visualization in Sketch. Include via an inline SVG rather than an `<img>` tag. Add a `TODO` in regards to an even cleaner setup post build refactoring. Resolves #1752 * chore: pick up vote fix and update yarn lock file * chore(vote): pick up another vote patch * Update index.md (#423) * update: git merge -> git rebase * Update index.md * Update README.md * Update .travis.yml * docs: fix formatting and grammar (#1765) Fix typos, improve grammar, and change `&nbsp;` to a normal space character. * docs(concepts): change loader order from chonological to reverse (#1767) When one starts to learn about loaders it's very confusing. [This](https://webpack.js.org/contribute/writing-a-loader/#complex-usage) explains the behaviour much better. * update UPDATE.md * #422 * https://github.com/webpack-china/webpack.js.org/issues/40
1 parent abfe9ae commit 6be1efe

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

src/content/guides/public-path.md

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
---
2-
title: Public Path
2+
title: 公共路径(Public Path)
33
sort: 24
44
contributors:
55
- rafaelrinaldi
66
- chrisVillanueva
77
- gonzoyumo
88
---
99

10-
The `publicPath` configuration option can be quite useful in a variety of scenarios. It allows you to specify the base path for all the assets within your application.
10+
webpack 提供一个非常有用的配置,该配置能帮助你为项目中的所有资源指定一个基础路径。它被称为`公共路径(publicPath)`
1111

1212

13-
## Use Cases
13+
## 示例
1414

15-
There are a few use cases in real applications where this feature becomes especially neat. Essentially, every file emitted to your `output.path` directory will be referenced from the `output.publicPath` location. This includes child chunks (created via [code splitting](/guides/code-splitting/)) and any other assets (e.g. images, fonts, etc.) that are a part of your dependency graph.
15+
这里提供一些示例,在实际应用中,这些示例的特性在实现的同时,还能保持高度整洁。
1616

17-
### Environment Based
17+
### 在构建项目时设置路径值
1818

19-
In development for example, we might have an `assets/` folder that lives on the same level of our index page. This is fine, but what if we wanted to host all these static assets on a CDN in production?
19+
在开发模式中,我们通常有一个 `assets/` 文件夹,它往往存放在和首页一个级别的目录下。这样是挺方便;但是如果在生产环境下,你想把这些静态文件统一使用CDN加载,那该怎么办?
2020

21-
To approach this problem you can easily use a good old environment variable. Let's say we have a variable `ASSET_PATH`:
21+
想要解决这个问题,你可以使用有着悠久历史的环境变量。比如说,我们设置了一个名为 `ASSET_PATH` 的变量:
2222

2323
``` js
2424
import webpack from 'webpack';
2525

26-
// Try the environment variable, otherwise use root
26+
// 如果预先定义过环境变量,就将其赋值给`ASSET_PATH`变量,否则赋值为根目录
2727
const ASSET_PATH = process.env.ASSET_PATH || '/';
2828

2929
export default {
@@ -32,30 +32,34 @@ export default {
3232
},
3333

3434
plugins: [
35-
// This makes it possible for us to safely use env vars on our code
35+
// 该插件帮助我们安心地使用环境变量
3636
new webpack.DefinePlugin({
3737
'process.env.ASSET_PATH': JSON.stringify(ASSET_PATH)
3838
})
3939
]
4040
};
4141
```
4242

43-
### On The Fly
43+
### 即时设定路径值
4444

45-
Another possible use case is to set the `publicPath` on the fly. webpack exposes a global variable called `__webpack_public_path__` that allows you to do that. So, in your application's entry point, you can simply do this:
45+
另一个可能出现的情况是,我们需要即时设置公共路径。webpack 提供一个全局变量供你设置,它名叫 `__webpack_public_path__`。所以在你的项目入口,你可以简单地设置如下:
4646

4747
```js
4848
__webpack_public_path__ = process.env.ASSET_PATH;
4949
```
5050

51-
That's all you need. Since we're already using the `DefinePlugin` on our
52-
configuration, `process.env.ASSET_PATH` will always be defined so we can safely
53-
do that.
51+
一切设置完成。因为我们已经在我们的配置项中使用了`DefinePlugin`
52+
`process.env.ASSET_PATH` 就已经被定义了,
53+
所以让我们能够安心地使用它了。
5454

55-
W> Be aware that if you use ES6 module imports in your entry file the `__webpack_public_path__` assignment will be done after the imports. In such cases, you'll have to move the public path assignment to its own dedicated module and then import it on top of your entry.js:
55+
**警告:**请注意,如果您在入口文件中使用 ES6 模块导入,则在导入后对 `__webpack_public_path__` 进行赋值。在这种情况下,您必须将公共路径(public path)赋值移至自己的专属模块,然后将其导入到您的 entry.js 之上:
5656

5757
```js
5858
// entry.js
5959
import './public-path';
6060
import './app';
6161
```
62+
63+
***
64+
65+
> 原文:https://webpack.js.org/guides/public-path/

0 commit comments

Comments
 (0)