How to expose Vue as global object

 ̄綄美尐妖づ 提交于 2021-02-10 23:23:19

问题


I am integrating legacy code with newer one, built with Webpack. In legacy code, plain js accessed Vue simply with: new Vue(...), from global scope. In Webpack, Vue will get sucked into vendor bundle and I would like to expose Vue back, so my legacy code would still see it as window.Vue

What I have done so far (webpack 3.x):

{
  test: require.resolve('vue/dist/vue.esm.js'), 
  use: [{loader: 'expose-loader',
         options: 'Vue'
   }]
 }

I get close with this, but I end up with window.Vue.default having the instance. How do I shim it further?


回答1:


If you can get it to window.Vue.default then how about just adding a line of code after that's available (but not within WebPacked js) that is

 app = window.Vue.default; 

Then Vue will be globally available from the app object.



来源:https://stackoverflow.com/questions/48775631/how-to-expose-vue-as-global-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!