How disable rel="prefetch" in dynamic route import?
I'm using @vue/cli 4.3.1 and Webpack 4.43.0, trying to disable prefetch:
in route.js
const Registration = () => import( /* webpackPrefetch: false */
/* webpackChunkName: "registration" */ '../modules/Popup/Registration.vue')
trying configure in vue.config.js, but not help
chainWebpack: config => {
config.plugins.delete('prefetch')
config.plugins.delete('prefetch-index') // or
config.plugins.delete('preload')
}
but anyway have
<link rel="prefetch" ....>
How disable rel="prefetch" in dynamic route import?
I'm using @vue/cli 4.3.1 and Webpack 4.43.0, trying to disable prefetch:
in route.js
const Registration = () => import( /* webpackPrefetch: false */
/* webpackChunkName: "registration" */ '../modules/Popup/Registration.vue')
trying configure in vue.config.js, but not help
chainWebpack: config => {
config.plugins.delete('prefetch')
config.plugins.delete('prefetch-index') // or
config.plugins.delete('preload')
}
but anyway have
<link rel="prefetch" ....>
Share
edited Oct 12, 2020 at 9:10
ux.engineer
11.4k15 gold badges69 silver badges114 bronze badges
asked Jun 2, 2020 at 10:53
SiviySiviy
691 silver badge8 bronze badges
4
- or const Registration = () => import( /* webpackPrefetch: -999 / / webpackChunkName: "registration" */ '../modules/Popup/Registration.vue') not help – Siviy Commented Jun 2, 2020 at 11:12
- Same issue here. Did you find a solution? – FrancescoMussi Commented Jun 8, 2020 at 12:56
- No not found solution – Siviy Commented Jun 15, 2020 at 22:17
- 1 if you're using SSR, it's configurable in createBundleRenderer - ssr.vuejs/api/#shouldprefetch – Ivan Ternovtsiy Commented Jul 8, 2020 at 10:12
1 Answer
Reset to default 4Vue CLI documentation for Preload states:
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()).
The hints are injected using @vue/preload-webpack-plugin and can be modified / deleted via chainWebpack as config.plugin('prefetch').
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'.
There is an issue opened because this documented solution has been outdated.
However, a working solutions is needing only slight modification as the plugins
property's structure has been changed. Here's an example elaborated with a multipage setup:
// File: vue.config.js
// Loading app's default title from a custom property in package.json
const { title } = require('./package.json');
module.exports = {
// You may omit this 'pages' property if not using multipage setup
pages: {
app: {
title,
entry: 'src/main.ts',
template: 'public/index.html',
filename: 'index.html',
excludeChunks: ['silentRenewOidc'],
},
silentRenewOidc: {
entry: 'src/silentRenewOidc.ts',
template: 'public/silent-renew.html',
filename: 'silent-renew.html',
excludeChunks: ['app'],
},
},
chainWebpack: (config) => {
// Disable prefetch and preload of async modules for 'app' page
config.plugins.store.delete('prefetch-app');
config.plugins.store.delete('preload-app');
// Use this syntax if not using multipage setup
// config.plugins.store.delete('prefetch');
// config.plugins.store.delete('preload');
},
};