Skip to content

Commit 14921e4

Browse files
gejgalisyyx990803
authored andcommitted
feat: disable Hot Reload option (#1036) (#1037)
1 parent 5f49ca6 commit 14921e4

File tree

5 files changed

+62
-4
lines changed

5 files changed

+62
-4
lines changed

docs/en/features/hot-reload.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,27 @@ When scaffolding the project with `vue-cli`, Hot Reload is enabled out-of-the-bo
1919
When manually setting up your project, hot-reload is enabled automatically when you serve your project with `webpack-dev-server --hot`.
2020

2121
Advanced users may want to check out [vue-hot-reload-api](https://github.com/vuejs/vue-hot-reload-api), which is used internally by `vue-loader`.
22+
23+
## Disabling Hot Reload
24+
25+
Hot Reload is always enabled except following situations:
26+
27+
* Webpack `target` is `node` (SSR)
28+
* Webpack minifies the code
29+
* `process.env.NODE_ENV === 'production'`
30+
31+
You may use `hotReload: false` option to disable the Hot Reload explicitly:
32+
33+
``` js
34+
module: {
35+
rules: [
36+
{
37+
test: /\.vue$/,
38+
loader: 'vue-loader',
39+
options: {
40+
hotReload: false // disables Hot Reload
41+
}
42+
}
43+
]
44+
}
45+
```

docs/en/options.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,3 +310,14 @@ Enable Vue 2.4 SSR compilation optimization that compiles part of the vdom trees
310310
- default: `true` in development mode, `false` in production mode.
311311

312312
Whether generate source maps with cache busting by appending a hash query to the file name. Turning this off can help with source map debugging.
313+
314+
### hotReload
315+
316+
> New in 13.5.0
317+
318+
- type: `boolean`
319+
- default: `true` in development mode, `false` in production mode or when the webpack config has `target: 'node'`.
320+
- allowed value: `false` (`true` will not force Hot Reload neither in production mode nor when `target: 'node'`)
321+
322+
Whether to use Webpack [Hot Module Replacement](https://webpack.js.org/concepts/hot-module-replacement/) to apply changes in the browser **without reloading the page**.
323+
Use this option (value `false`) to disable the Hot Reload feature in development mode.

lib/loader.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,7 @@ module.exports = function (content) {
143143
const postLoaders = options.postLoaders || {}
144144

145145
const needsHotReload =
146-
!isServer && !isProduction && (parts.script || parts.template)
147-
146+
!isServer && !isProduction && (parts.script || parts.template) && options.hotReload !== false
148147
if (needsHotReload) {
149148
output += 'var disposed = false\n'
150149
}

lib/template-compiler/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = function (html) {
1313
const isProduction = this.minimize || process.env.NODE_ENV === 'production'
1414
const vueOptions = this.options.__vueOptions__ || {}
1515
const options = loaderUtils.getOptions(this) || {}
16-
16+
const needsHotReload = !isServer && !isProduction && vueOptions.hotReload !== false
1717
const defaultModules = [transformRequire(options.transformToRequire), transformSrcset()]
1818
let userModules = vueOptions.compilerModules || options.compilerModules
1919

@@ -90,7 +90,7 @@ module.exports = function (html) {
9090
: `module.exports = ${exports}`
9191
}
9292
// hot-reload
93-
if (!isServer && !isProduction) {
93+
if (needsHotReload) {
9494
const exportsName = vueOptions.esModule ? 'esExports' : 'module.exports'
9595
code +=
9696
'\nif (module.hot) {\n' +

test/test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,4 +1027,28 @@ describe('vue-loader', () => {
10271027
vnode.children[6].data.on.click()
10281028
})
10291029
})
1030+
1031+
it('hot reload enabled', done => {
1032+
bundle({
1033+
entry: './test/fixtures/basic.vue',
1034+
vue: {
1035+
hotReload: true
1036+
}
1037+
}, (code) => {
1038+
expect(code).to.contains('require("vue-hot-reload-api")')
1039+
done()
1040+
})
1041+
})
1042+
1043+
it('hot reload disabled', done => {
1044+
bundle({
1045+
entry: './test/fixtures/basic.vue',
1046+
vue: {
1047+
hotReload: false
1048+
}
1049+
}, (code) => {
1050+
expect(code).not.to.contains('require("vue-hot-reload-api")')
1051+
done()
1052+
})
1053+
})
10301054
})

0 commit comments

Comments
 (0)