]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
feat(devtools): support multiple router instances
authorEduardo San Martin Morote <posva13@gmail.com>
Thu, 10 Sep 2020 14:47:13 +0000 (16:47 +0200)
committerEduardo San Martin Morote <posva@users.noreply.github.com>
Wed, 4 Nov 2020 21:19:57 +0000 (22:19 +0100)
rollup.config.js
src/devtools.ts

index 499c6d353231cb7d50596748a37323470f302a90..d4f14c8c328059d16049939c5884c53596201201 100644 (file)
@@ -64,7 +64,7 @@ function createConfig(format, output, plugins = []) {
   output.sourcemap = !!process.env.SOURCE_MAP
   output.banner = banner
   output.externalLiveBindings = false
-  output.globals = { vue: 'Vue' }
+  output.globals = { vue: 'Vue', '@vue/devtools-api': 'VueDevtoolsApi' }
 
   const isProductionBuild = /\.prod\.js$/.test(output.file)
   const isGlobalBuild = format === 'global'
@@ -94,7 +94,7 @@ function createConfig(format, output, plugins = []) {
   // during a single build.
   hasTSChecked = true
 
-  const external = ['vue']
+  const external = ['vue', '@vue/devtools-api']
 
   const nodePlugins = [resolve(), commonjs()]
 
index b0bdab99b107ed8e24c4af412b4e25e9025a382c..f3f77b6b725b77832bd643305026bc3c6ee0c5ac 100644 (file)
@@ -44,12 +44,17 @@ function formatDisplay(display: string) {
   }
 }
 
+// to support multiple router instances
+let routerId = 0
+
 export function addDevtools(app: App, router: Router, matcher: RouterMatcher) {
   // Take over router.beforeEach and afterEach
 
+  // increment to support multiple router instances
+  const id = routerId++
   setupDevtoolsPlugin(
     {
-      id: 'Router',
+      id: 'Router' + id ? ' ' + id : '',
       label: 'Router devtools',
       app,
     },
@@ -73,11 +78,11 @@ export function addDevtools(app: App, router: Router, matcher: RouterMatcher) {
         api.notifyComponentUpdate()
       })
 
-      const navigationsLayerId = 'router:navigations'
+      const navigationsLayerId = 'router:navigations:' + id
 
       api.addTimelineLayer({
         id: navigationsLayerId,
-        label: 'Router Navigations',
+        label: `Router${id ? ' ' + id : ''} Navigations`,
         color: 0x40a8c4,
       })
 
@@ -159,11 +164,11 @@ export function addDevtools(app: App, router: Router, matcher: RouterMatcher) {
         })
       })
 
-      const routerInspectorId = 'router-inspector'
+      const routerInspectorId = 'router-inspector:' + id
 
       api.addInspector({
         id: routerInspectorId,
-        label: 'Routes',
+        label: 'Routes' + id ? ' ' + id : '',
         icon: 'book',
         treeFilterPlaceholder: 'Search routes',
       })