简体   繁体   中英

Webpack imports from entry file, not available in dist/index.html

I have imports in index.js

import Vue from 'vue';
import axios from "axios";
import jQuery from "jQuery";
window.Vue = Vue;
var $ = jQuery;

Vue.use(axios);

export {$, Vue};

Then in my dist folder i have an index.html loading the main.js file that webpack outputs

   <div id="app">
        
   </div>
   <script src="main.js"></script>
   <script>
    console.log(Vue);
    console.log(window.Vue);
   </script>

Obviously I have access to window.Vue, but why don't I have access to just Vue?

Im new to webpack. Is there something i need to do?

export doesn't implicitly make properties available in the global scope, it allows them to be import ed elsewhere. If you want $ and Vue attached to the window, you need to do that explicitly in index.js .

window.Vue = Vue;
window.$ = $;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM