You can use hotReload: false option to disable the Hot Reload explicitly.
It can be configured as below,
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
hotReload: false // disables Hot Reload
}
}
]
}
You can use hotReload: false option to disable the Hot Reload explicitly.
It can be configured as below,
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
hotReload: false // disables Hot Reload
}
}
]
}
Question 122
The vue loader plugin internally uses hot reloading. If you are scaffolding project with vue-cli, hot reloading
comes out of the box but if you are manually setting up the project then hot reloading is enabled by default with
webpack-dev-server --hot command.
Below are the state preservation rules in hot reloading,
<template> of a component, instances of the edited component will re-render in place,
preserving all current private state.<script> part of a component, instances of the edited component will be destroyed and
re-created in place.<style> hot reload operates on its own via vue-style-loader without affecting application
state.You can create functional components by adding functional attribute to template block,
<template functional>
</template>
If you need to access properties defined globally on Vue.prototype then you can access them on parent,
<template functional>
</template>
Question 126
You can perform testing in two ways,
Question 127
The stylelint linter supports linting style parts of Vue single file components. You can run linter on particular vue file as below,
stylelint MyComponent.vue
Other option is configuring stylelint-webpack-plugin in webpack. It can be configured as a dev dependency.
// webpack.config.js
const StyleLintPlugin = require('stylelint-webpack-plugin');
module.exports = {
// ... other options
plugins: [
new StyleLintPlugin({
files: ['**/*.{vue,htm,html,css,sss,less,scss,sass}'],
})
]
}
Question 128
The official eslint-plugin-vue supports linting both the template and script parts of Vue single file components.
You can configure plugin in your ESLint config,
// .eslintrc.js
module.exports = {
extends: [
"plugin:vue/essential"
]
}
You can run linter on particular component as below,
eslint --ext js,vue MyComponent.vue
Question 129
You can use eslint-loader for *.vue files in order to automatically linted on save during development. It can be
installed as npm module,
npm install -D eslint eslint-loader
After that you need to add it as pre-loader,
// webpack.config.js
module.exports = {
// ... other options
module: {
rules: [
{
enforce: 'pre',
test: /\.(js|vue)$/,
loader: 'eslint-loader',
exclude: /node_modules/
}
]
}
}
Question 130
CSS Extraction is used to extract all the processed CSS in all Vue components into a single CSS file. For
webpack4, you need to install below npm command,
npm install -D mini-css-extract-plugin
You can configure this plugin in webpack as below,
// webpack.config.js
var MiniCssExtractPlugin = require('mini-css-extract-plugin')
module.exports = {
// other options...
module: {
rules: [
// ... other rules omitted
{
test: /\.css$/,
use: [
process.env.NODE_ENV !== 'production'
? 'vue-style-loader'
: MiniCssExtractPlugin.loader,
'css-loader'
]
}
]
},
plugins: [
// ... Vue Loader plugin omitted
new MiniCssExtractPlugin({
filename: 'style.css'
})
]
}
Question 131
You can define custom language blocks inside *.vue files based on the lang attribute of the block, the block's
tag name, and the rules in your webpack config. You can also use resourceQuery to match a rule against a custom
block with no lang.
For example, to match against <message> custom blocks.
{
module: {
rules: [
{
resourceQuery: /blockType=message/,
loader: 'loader-to-use'
}
]
}
}
Question 132
Below are the list of major stylelint features
Vuex enforces below rules to structure any application.
The project structure for any non-trivial application would be as below,
Question 134
Yes, vuex supports hot-reloading for mutations, modules, actions and getters during development. You need to use either webpack's hot module replacement API or browserify's hot module replacement plugin.
The store.hotUpdate() API method is used for mutations and modules.
For example, you need to configure vuex store as below,
// store.js
import Vue from 'vue'
import Vuex from 'vuex'
import mutations from './mutations'
import myModule from './modules/myModule'
Vue.use(Vuex)
const state = { message: "Welcome to hot reloading" }
const store = new Vuex.Store({
state,
mutations,
modules: {
moduleA: myModule
}
})
if (module.hot) {
// accept actions and mutations as hot modules
module.hot.accept(['./mutations', './modules/newMyModule'], () => {
// Get the updated modules
const newMutations = require('./mutations').default
const newMyModule = require('./modules/myModule').default
//swap in the new modules and mutations
store.hotUpdate({
mutations: newMutations,
modules: {
moduleA: newMyModule
}
})
})
}