Answer the question
In order to leave comments, you need to log in
How to force VUE to load dynamic components from CDN?
anyone know if it's possible to force vue to load dynamic components via cdn in production?
this is how the vue script file itself
is loaded, this is how the dynamic component is loaded
directly from the server.
the component itself
Vue.component('page-projects', (resolve) => {
return require.ensure([], (require) => {
return resolve(require('./components/pages/projects/index.vue'));
}, "components/pages/projects/index");
});
Answer the question
In order to leave comments, you need to log in
Vue
uses webpack
, but webpack
uses specific paths for requests that you specify when building.
Head- on solution: a special build for cdn, where the parameter publicPatch
points to the corresponding site.
The solution is tricky:webpack
it allows you to change the public path dynamically by assigning it to the __webpack_public_path__
. All that remains is to get the path to the script at the start of the application, for example from document.currentScript
, select the desired path from it and assign it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question