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: Translation Japanese #4934

Open
wants to merge 45 commits into
base: dev
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
b2b7d33
copy docs/ja/config/README.md
tiwuofficial Dec 4, 2019
9e8aacc
copy docs/ja/README.md
tiwuofficial Dec 4, 2019
930420e
copy docs/ja/core-plugins/babel.md
tiwuofficial Dec 4, 2019
506e7c1
copy docs/ja/core-plugins/README.md
tiwuofficial Dec 4, 2019
ef008d3
copy docs/ja/core-plugins/e2e-cypress.md
tiwuofficial Dec 5, 2019
1aa1984
copy docs/ja/core-plugins/e2e-nightwatch.md
tiwuofficial Dec 5, 2019
a85300b
copy docs/ja/core-plugins/eslint.md
tiwuofficial Dec 5, 2019
60e9789
copy docs/ja/core-plugins/pwa.md
tiwuofficial Dec 5, 2019
34512b0
copy docs/ja/core-plugins/router.md
tiwuofficial Dec 5, 2019
4f29567
copy docs/ja/core-plugins/typescript.md
tiwuofficial Dec 5, 2019
df3d8b6
copy docs/ja/core-plugins/unit-jest.md
tiwuofficial Dec 5, 2019
2c04e86
copy docs/ja/core-plugins/unit-mocha.md
tiwuofficial Dec 5, 2019
af1408f
copy docs/ja/core-plugins/vuex.md
tiwuofficial Dec 5, 2019
dde28df
copy docs/ja/dev-guide/generator-api.md
tiwuofficial Dec 5, 2019
87c2f32
copy docs/ja/dev-guide/plugin-api.md
tiwuofficial Dec 5, 2019
1c3d57f
copy docs/ja/dev-guide/plugin-dev.md
tiwuofficial Dec 6, 2019
0670cb0
copy docs/ja/dev-guide/ui-api.md
tiwuofficial Dec 6, 2019
8c0f57c
copy docs/ja/dev-guide/ui-info.md
tiwuofficial Dec 6, 2019
ffda3c0
copy docs/ja/dev-guide/ui-localization.md
tiwuofficial Dec 6, 2019
9de2ddb
copy docs/ja/guide/README.md
tiwuofficial Dec 6, 2019
b8bacb1
copy docs/ja/guide/browser-compatibility.md
tiwuofficial Dec 6, 2019
81a7ed5
copy docs/ja/guide/build-targets.md
tiwuofficial Dec 6, 2019
99114e1
copy docs/ja/guide/cli-service.md
tiwuofficial Dec 6, 2019
f558d1f
copy docs/ja/guide/creating-a-project.md
tiwuofficial Dec 6, 2019
4a0dd32
copy docs/ja/guide/css.md
tiwuofficial Dec 6, 2019
c48aafa
copy docs/ja/guide/deployment.md
tiwuofficial Dec 6, 2019
c57e63c
copy docs/ja/guide/html-and-static-assets.md
tiwuofficial Dec 6, 2019
e753088
copy docs/ja/guide/installation.md
tiwuofficial Dec 6, 2019
e09eaf5
copy docs/ja/guide/mode-and-env.md
tiwuofficial Dec 6, 2019
a3b7361
copy docs/ja/guide/plugins-and-presets.md
tiwuofficial Dec 6, 2019
e74403e
copy docs/ja/guide/prototyping.md
tiwuofficial Dec 6, 2019
9cc7469
copy docs/ja/guide/troubleshooting.md
tiwuofficial Dec 6, 2019
a787bd5
copy docs/ja/guide/webpack.md
tiwuofficial Dec 6, 2019
62e05a8
copy docs/ja/migrating-from-v3/README.md
tiwuofficial Dec 6, 2019
5bc4476
copy docs/.vuepress/config.js
tiwuofficial Dec 6, 2019
f822c12
translation from en into ja docs/.vuepress/config.js
tiwuofficial Dec 6, 2019
fa087c7
translation from en into ja docs/ja/README.md
tiwuofficial Dec 6, 2019
672849a
完全に構成可能 -> 設定可能
tiwuofficial Dec 10, 2019
bc67624
単一のVueファイル -> 単一ファイルコンポーネント
tiwuofficial Dec 10, 2019
3888872
将来の準備 -> 将来に向けて
tiwuofficial Dec 10, 2019
410a2b6
translation from en into ja docs/ja/core-plugins/README.md
tiwuofficial Dec 13, 2019
3028af4
Revert "translation from en into ja docs/ja/core-plugins/README.md"
tiwuofficial Dec 13, 2019
bd75e3e
translation from en into ja docs/ja/core-plugins/README.md
tiwuofficial Dec 13, 2019
1e8e701
translation from en into ja docs/ja/core-plugins/vuex.md
tiwuofficial Jan 8, 2020
7ed51a6
translation from en into ja docs/ja/core-plugins/router.md
tiwuofficial Jan 16, 2020
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
Prev Previous commit
Next Next commit
copy docs/ja/guide/html-and-static-assets.md
  • Loading branch information
tiwuofficial committed Dec 6, 2019
commit c57e63c1a58eedaf7f52cb28df3374b85316361a
201 changes: 201 additions & 0 deletions docs/ja/guide/html-and-static-assets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
# HTML and Static Assets

## HTML

### The Index File

The file `public/index.html` is a template that will be processed with [html-webpack-plugin](https://github.com/jantimon/html-webpack-plugin). During build, asset links will be injected automatically. In addition, Vue CLI also automatically injects resource hints (`preload/prefetch`), manifest/icon links (when PWA plugin is used), and the asset links for the JavaScript and CSS files produced during the build.

### Interpolation

Since the index file is used as a template, you can use the [lodash template](https://lodash.com/docs/4.17.10#template) syntax to interpolate values in it:

- `<%= VALUE %>` for unescaped interpolation;
- `<%- VALUE %>` for HTML-escaped interpolation;
- `<% expression %>` for JavaScript control flows.

In addition to the [default values exposed by `html-webpack-plugin`](https://github.com/jantimon/html-webpack-plugin#writing-your-own-templates), all [client-side env variables](./mode-and-env.md#using-env-variables-in-client-side-code) are also available directly. For example, to use the `BASE_URL` value:

``` html
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
```

See also:
- [publicPath](../config/#publicpath)

### Preload

[`<link rel="preload">`](https://developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content) is a type of resource hint that is used to specify resources that your pages will need very soon after loading, which you therefore want to start preloading early in the lifecycle of a page load, before the browser's main rendering machinery kicks in.

By default, a Vue CLI app will automatically generate preload hints for all files that are needed for the initial rendering of your app.

The hints are injected using [@vue/preload-webpack-plugin](https://github.com/vuejs/preload-webpack-plugin) and can be modified / deleted via `chainWebpack` as `config.plugin('preload')`.

### Prefetch

[`<link rel="prefetch">`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Link_prefetching_FAQ) is a type of resource hint that tells the browser to prefetch content that the user may visit in the near future in the browser's idle time, after the page finishes loading.

By default, a Vue CLI app will automatically generate prefetch hints for all JavaScript files generated for async chunks (as a result of [on-demand code splitting via dynamic `import()`](https://webpack.js.org/guides/code-splitting/#dynamic-imports)).

The hints are injected using [@vue/preload-webpack-plugin](https://github.com/vuejs/preload-webpack-plugin) and can be modified / deleted via `chainWebpack` as `config.plugin('prefetch')`.

::: tip Note for multi page setups
When using a multipage setup, the plugin name above should be changed to match the structure 'prefetch-{pagename}', for example 'prefetch-app'.
:::

Example:

``` js
// vue.config.js
module.exports = {
chainWebpack: config => {
// remove the prefetch plugin
config.plugins.delete('prefetch')

// or:
// modify its options:
config.plugin('prefetch').tap(options => {
options[0].fileBlacklist = options[0].fileBlacklist || []
options[0].fileBlacklist.push(/myasyncRoute(.)+?\.js$/)
return options
})
}
}
```

When the prefetch plugin is disabled, you can manually select specific chunks to prefetch using webpack's inline comments:

``` js
import(/* webpackPrefetch: true */ './someAsyncComponent.vue')
```

webpack's runtime will inject prefetch links when the parent chunk is loaded.

::: tip
Prefetch links will consume bandwidth. If you have a large app with many async chunks and your users are primarily mobile and thus bandwidth-aware, you may want to disable prefetch links and manually select chunks to prefetch.
:::

### Disable Index Generation

When using Vue CLI with an existing backend, you may need to disable the generation of `index.html` so that the generated assets can be used in a server-rendered page. To do so, the following can be added to [`vue.config.js`](../config/#vue-config-js):

``` js
// vue.config.js
module.exports = {
// disable hashes in filenames
filenameHashing: false,
// delete HTML related webpack plugins
chainWebpack: config => {
config.plugins.delete('html')
config.plugins.delete('preload')
config.plugins.delete('prefetch')
}
}
```

However, this is not really recommended because:

- Hard-coded file names makes it more difficult to implement efficient cache control.
- Hard-coded file names also do not play well with code-splitting, which generates additional JavaScript files with varying filenames.
- Hard-coded file names do not work with [Modern Mode](../guide/browser-compatibility.md#modern-mode).

Instead, you should consider using the [indexPath](../config/#indexpath) option to use the generated HTML as a view template in your server-side framework.

### Building a Multi-Page App

Not every app has to be an SPA. Vue CLI supports building a multi-paged app using the [`pages` option in `vue.config.js`](../config/#pages). The built app will efficiently share common chunks between multiple entries for optimal loading performance.

## Static Assets Handling

Static assets can be handled in two different ways:

- Imported in JavaScript or referenced in templates/CSS via relative paths. Such references will be handled by webpack.

- Placed in the `public` directory and referenced via absolute paths. These assets will simply be copied and not go through webpack.

### Relative Path Imports

When you reference a static asset using relative path (must start with `.`) inside JavaScript, CSS or `*.vue` files, the asset will be included into webpack's dependency graph. During this compilation process, all asset URLs such as `<img src="...">`, `background: url(...)` and CSS `@import` are **resolved as module dependencies**.

For example, `url(./image.png)` will be translated into `require('./image.png')`, and

``` html
<img src="./image.png">
```

will be compiled into:

``` js
h('img', { attrs: { src: require('./image.png') }})
```

Internally, we use `file-loader` to determine the final file location with version hashes and correct public base paths, and use `url-loader` to conditionally inline assets that are smaller than 4kb, reducing the amount of HTTP requests.

You can adjust the inline file size limit via [chainWebpack](../config/#chainwebpack). For example, to set the limit to 10kb instead:

``` js
// vue.config.js
module.exports = {
chainWebpack: config => {
config.module
.rule('images')
.use('url-loader')
.loader('url-loader')
.tap(options => Object.assign(options, { limit: 10240 }))
}
}
```

### URL Transform Rules

- If the URL is an absolute path (e.g. `/images/foo.png`), it will be preserved as-is.

- If the URL starts with `.`, it's interpreted as a relative module request and resolved based on the folder structure on your file system.

- If the URL starts with `~`, anything after it is interpreted as a module request. This means you can even reference assets inside node modules:

``` html
<img src="~some-npm-package/foo.png">
```

- If the URL starts with `@`, it's also interpreted as a module request. This is useful because Vue CLI by default aliases `@` to `<projectRoot>/src`. **(templates only)**

### The `public` Folder

Any static assets placed in the `public` folder will simply be copied and not go through webpack. You need to reference them using absolute paths.

Note we recommend importing assets as part of your module dependency graph so that they will go through webpack with the following benefits:

- Scripts and stylesheets get minified and bundled together to avoid extra network requests.
- Missing files cause compilation errors instead of 404 errors for your users.
- Result filenames include content hashes so you don’t need to worry about browsers caching their old versions.

The `public` directory is provided as an **escape hatch**, and when you reference it via absolute path, you need to take into account where your app will be deployed. If your app is not deployed at the root of a domain, you will need to prefix your URLs with the [publicPath](../config/#publicpath):

- In `public/index.html` or other HTML files used as templates by `html-webpack-plugin`, you need to prefix the link with `<%= BASE_URL %>`:

``` html
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
```

- In templates, you will need to first pass the base URL to your component:

``` js
data () {
return {
publicPath: process.env.BASE_URL
}
}
```

Then:

``` html
<img :src="`${publicPath}my-image.png`">
```

### When to use the `public` folder

- You need a file with a specific name in the build output.
- You have thousands of images and need to dynamically reference their paths.
- Some library may be incompatible with Webpack and you have no other option but to include it as a `<script>` tag.