问题
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