Skip to content

Instantly share code, notes, and snippets.

@Kolobok12309
Last active September 21, 2021 17:01
Show Gist options
  • Save Kolobok12309/685d00c8e51dbd3e450909238836575d to your computer and use it in GitHub Desktop.
Save Kolobok12309/685d00c8e51dbd3e450909238836575d to your computer and use it in GitHub Desktop.
Helper for enabling vue devtools for production builds
// ==UserScript==
// @name VueEnableDevtools
// @namespace http://tampermonkey.net/
// @version 1.1
// @description Add helper for enabling vue devtools for production builds
// @source https://gist.github.com/Kolobok12309/685d00c8e51dbd3e450909238836575d
// @author Kolobok12309
// @include *
// @grant unsafeWindow
// ==/UserScript==
(function(global) {
'use strict';
global.__enableVueDevTools__ = function() {
let vueDetected = false;
const nuxtDetected = Boolean(global.__NUXT__ || global.$nuxt);
let vueInstance = null;
if (nuxtDetected) {
vueDetected = true;
vueInstance = global.$nuxt;
} else {
const all = document.querySelectorAll('*');
let el;
for (let elem of all) {
if (elem.__vue__) {
el = elem;
break;
}
}
if (el) {
vueDetected = true;
vueInstance = el.__vue__.$root;
}
}
if (!vueDetected) throw new Error('Vue not detected');
if (!global.__VUE_DEVTOOLS_GLOBAL_HOOK__) throw new Error('VUE_DEVTOOLS_GLOBAL_HOOK not found')
const Vue = vueInstance.constructor;
Vue.config.devtools = true;
Vue.config.productionTip = true;
global.__VUE_DEVTOOLS_GLOBAL_HOOK__.Vue = Vue;
global.postMessage({
devtoolsEnabled: vueDetected,
vueDetected,
nuxtDetected,
}, '*');
return {
Vue,
vueInstance,
vueDetected,
nuxtDetected,
};
};
})(unsafeWindow)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment