new webpack.ProvidePlugin vue模块化的全局引用
目前在vue-cli2运用
webpack.base.conf.js
new webpack.ProvidePlugin({ jQuery: 'jquery', $: 'jquery', Gdata: ['@/api/index.js', 'default'], RequestApi: resolve('/static/config/index.js') })
static/config/index.js
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
const peconfig = 'devCompXs'; switch (peconfig) { case 'devPloce': var DUTY_URL_INTERNET = '//10.95.1.210:10021'; var WEBSOCKET_INTERNET = 'ws://10.95.1.210:10021/commonwebsocket/channels/test'; var MAPCONTROL_SOCKET_INTERNET = 'ws://10.95.1.210:10021/websocket/mapControl/127.0.0.1'; //这条目前没有业务用注释着 var VIDEO_SOCKET_INTERNET = 'ws://10.95.1.210:10021/websocket/vidoControl/127.0.0.1'; var MESSAGE_SOCKET_INTERNET = 'ws://10.95.1.210:10021/websocket/message/127.0.0.1'; //这条目前没有业务用注释着 //其他资源 var MAP_URL_INTERNET = 'http://114.215.146.210:25003/v3/tile?z={z}&x={x}&y={y}'; var TRAFFIC_URL_INTERNET = 'https://api.mapbox.com/styles/v1/banterise/cjhvkka84004g2rpn9cw8ng90/tiles/256/{z}/{x}/{y}@2x?access_token=pk.eyJ1IjoiYmFudGVyaXNlIiwiYSI6ImNpaXNrNzRidjAzOGZ2NG01d3ozcmt6cW4ifQ.V--rLvOufK9nTJdRoAm_Pw'; var VIDEOWPZ = 'http://10.168.31.222/download/VideoWebPlugin.exe'; var MAPCONFIG_INTERNET = { center: [34.2778, 108.953098], zoom: 13 }; break; case 'devCompBd': var DUTY_URL_INTERNET = '//10.168.31.96:10021'; var WEBSOCKET_INTERNET = 'ws://10.168.31.96:10021/commonwebsocket/channels/test'; var MAPCONTROL_SOCKET_INTERNET = 'ws://10.168.31.96:10021/websocket/mapControl/127.0.0.1'; var VIDEO_SOCKET_INTERNET = 'ws://10.168.31.96:10021/websocket/vidoControl/127.0.0.1'; var MESSAGE_SOCKET_INTERNET = 'ws://10.168.31.96:10021/websocket/message/127.0.0.1'; //其他资源 var MAP_URL_INTERNET = 'http://114.215.146.210:25003/v3/tile?z={z}&x={x}&y={y}'; var TRAFFIC_URL_INTERNET = 'https://api.mapbox.com/styles/v1/banterise/cjhvkka84004g2rpn9cw8ng90/tiles/256/{z}/{x}/{y}@2x?access_token=pk.eyJ1IjoiYmFudGVyaXNlIiwiYSI6ImNpaXNrNzRidjAzOGZ2NG01d3ozcmt6cW4ifQ.V--rLvOufK9nTJdRoAm_Pw'; var VIDEOWPZ = 'http://10.168.31.222/download/VideoWebPlugin.exe'; var MAPCONFIG_INTERNET = { center: [34.2778, 108.953098], zoom: 13 }; break; case 'devCompXs': var DUTY_URL_INTERNET = '//10.168.31.3:9111'; var WEBSOCKET_INTERNET = 'ws://10.168.31.3:9111/commonwebsocket/channels/test'; var MAPCONTROL_SOCKET_INTERNET = 'ws://10.168.31.3:9111/websocket/mapControl/127.0.0.1'; var VIDEO_SOCKET_INTERNET = 'ws://10.168.31.3:9111/websocket/vidoControl/127.0.0.1'; var MESSAGE_SOCKET_INTERNET = 'ws://10.168.31.3:9111/websocket/message/127.0.0.1'; //其他资源 var MAP_URL_INTERNET = 'http://114.215.146.210:25003/v3/tile?z={z}&x={x}&y={y}'; var TRAFFIC_URL_INTERNET = 'https://api.mapbox.com/styles/v1/banterise/cjhvkka84004g2rpn9cw8ng90/tiles/256/{z}/{x}/{y}@2x?access_token=pk.eyJ1IjoiYmFudGVyaXNlIiwiYSI6ImNpaXNrNzRidjAzOGZ2NG01d3ozcmt6cW4ifQ.V--rLvOufK9nTJdRoAm_Pw'; var VIDEOWPZ = 'http://10.168.31.222/download/VideoWebPlugin.exe'; var MAPCONFIG_INTERNET = { center: [34.2778, 108.953098], zoom: 13 }; break; case 'production': var DUTY_URL_INTERNET = '//10.95.1.120:10011'; //服务地址 var WEBSOCKET_INTERNET = 'ws://10.95.1.120:10011/commonwebsocket/channels/test'; //实车socket var MAPCONTROL_SOCKET_INTERNET = 'ws://10.95.1.120:10011/websocket/mapControl/127.0.0.1'; var VIDEO_SOCKET_INTERNET = 'ws://10.95.1.120:10011/websocket/vidoControl/127.0.0.1'; //4分屏前三个socket var MESSAGE_SOCKET_INTERNET = 'ws://10.95.1.120:10011/websocket/message/127.0.0.1'; var VIDEOWPZ = 'http://10.95.1.120:9111/VideoWebPlugin.exe'; //下载视频资源 var TRAFFIC_URL_INTERNET = 'http://114.215.146.210:25003/v3/tile?z={z}&x={x}&y={y}'; var MAP_URL_INTERNET = 'http://10.95.1.104/xian/m/{z}/{x}/{y}.png'; var MAPCONFIG_INTERNET = { center: [34.2778, 108.953098], zoom: 13 }; break; } export { DUTY_URL_INTERNET, // 配置服务器地址, WEBSOCKET_INTERNET, MAPCONTROL_SOCKET_INTERNET, VIDEO_SOCKET_INTERNET, MESSAGE_SOCKET_INTERNET, MAP_URL_INTERNET, TRAFFIC_URL_INTERNET, VIDEOWPZ, MAPCONFIG_INTERNET };