Skip to content

Commit 77f7f9a

Browse files
committed
docs: filenameHashing
1 parent 92473e9 commit 77f7f9a

File tree

2 files changed

+33
-53
lines changed

2 files changed

+33
-53
lines changed

docs/config/README.md

Lines changed: 7 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ module.exports = {
8383

8484
Specify the output path for the generated `index.html` (relative to `outputDir`). Can also be an absolute path.
8585

86+
### filenameHashing
87+
88+
- Type: `boolean`
89+
- Default: `true`
90+
91+
By default, generated static assets contains hashes in their filenames for better caching control. However, this requires the index HTML to be auto-generated by Vue CLI. If you cannot make use of the index HTML generated by Vue CLI, you can disable filename hashing by setting this option to `false`.
92+
8693
### pages
8794

8895
- Type: `Object`
@@ -365,56 +372,3 @@ See [@vue/cli-plugin-e2e-cypress](https://github.com/vuejs/vue-cli/tree/dev/pack
365372
### Nightwatch
366373

367374
See [@vue/cli-plugin-e2e-nightwatch](https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-e2e-nightwatch) for more details.
368-
369-
## Example Configurations
370-
371-
### Disable Hashed Filenames
372-
373-
While generated static asset filenames contain a hash to [ensure the browser picks up changed files](https://webpack.js.org/guides/caching/#output-filenames) this can be disabled. One common scenario for this is when integrating Vue with a backend that dictates a code structure other than what Vue CLI generates, such as with WordPress or Laravel. To disable the hashed filenames, the following can be added to [`vue.config.js`](#vue-config-js):
374-
375-
``` js
376-
// vue.config.js
377-
module.exports = {
378-
chainWebpack: (config) => {
379-
config.module
380-
.rule('images')
381-
.use('url-loader')
382-
.tap(options => Object.assign({}, options, { name: 'img/[name].[ext]' }));
383-
},
384-
css: {
385-
extract: {
386-
filename: '/css/[name].css',
387-
chunkFilename: '/css/[name].css',
388-
},
389-
},
390-
configureWebpack: {
391-
output: {
392-
filename: 'js/[name].js',
393-
chunkFilename: 'js/[name].js',
394-
},
395-
},
396-
};
397-
```
398-
399-
::: tip
400-
When manually overwriting `filename` or `chunkFilename`, `assetsDir` does not need to be included in their path values.
401-
:::
402-
403-
### Disable Generating index.html
404-
405-
When using Vue CLI with an existing backend, you may need to disable the generation of `index.html` so that they generated assets can be used with another default document. To do so, the following can be added to [`vue.config.js`](#vue-config-js):
406-
407-
``` js
408-
// vue.config.js
409-
module.exports = {
410-
chainWebpack: config => {
411-
config.plugins.delete('html')
412-
config.plugins.delete('preload')
413-
config.plugins.delete('prefetch')
414-
}
415-
}
416-
```
417-
418-
::: warning
419-
[Modern Mode](../guide/browser-compatibility.md#modern-mode) will not work when the `html-webpack-plugin` is disabled.
420-
:::

docs/guide/html-and-static-assets.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,32 @@ webpack's runtime will inject prefetch links when the parent chunk is loaded.
7070
Prefetch links will consume bandwidth. If you have a large app with many async chunks and your user are primarily mobile and thus bandwidth-aware, you may want to disable prefetch links and manually select chunks to prefetch.
7171
:::
7272

73+
### Disable Index Generation
74+
75+
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`](#vue-config-js):
76+
77+
``` js
78+
// vue.config.js
79+
module.exports = {
80+
// disable hashes in filenames
81+
filenameHashing: false,
82+
// delete HTML related webpack plugins
83+
chainWebpack: config => {
84+
config.plugins.delete('html')
85+
config.plugins.delete('preload')
86+
config.plugins.delete('prefetch')
87+
}
88+
}
89+
```
90+
91+
However, this is not really recommended because:
92+
93+
- Hard-coded file names makes it more difficult to implement efficient cache control.
94+
- Hard-coded file names also do not play well with code-splitting, which generates additional JavaScript files with varying filenames.
95+
- Hard-coded file names do not work with [Modern Mode](../guide/browser-compatibility.md#modern-mode).
96+
97+
Instead, you should consider using the [indexPath](../config/#indexpath) option to use the generated HTML as a view template in your server-side framework.
98+
7399
### Building a Multi-Page App
74100

75101
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.

0 commit comments

Comments
 (0)