]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
build(devtools): externalize devtools
authorEduardo San Martin Morote <posva13@gmail.com>
Thu, 13 May 2021 08:28:48 +0000 (10:28 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Thu, 13 May 2021 08:28:48 +0000 (10:28 +0200)
package.json
rollup.config.js
src/createPinia.ts
src/store.ts
yarn.lock

index 5d0d760cc896946b32c344ab0369ea30661da006..abf4a8e1b901d2e2c81e1761a7b747e9a55bada1 100644 (file)
@@ -70,7 +70,6 @@
     "@sucrase/jest-plugin": "^2.1.0",
     "@types/jest": "^26.0.23",
     "@types/node": "^15.0.2",
-    "@vue/devtools-api": "^6.0.0-beta.9",
     "@vue/server-renderer": "^3.0.11",
     "@vue/test-utils": "^2.0.0-rc.6",
     "brotli": "^1.3.2",
@@ -90,6 +89,9 @@
     "vue": "^3.0.11",
     "yorkie": "^2.0.0"
   },
+  "dependencies": {
+    "@vue/devtools-api": "^6.0.0-beta.10"
+  },
   "gitHooks": {
     "pre-commit": "lint-staged",
     "commit-msg": "node scripts/verifyCommit.js"
index 8a85437d7627369d1be05f3865303d5d5cd9cdcf..96c025edee63c968a30656f62d73148bb9ba0e7b 100644 (file)
@@ -108,6 +108,9 @@ function createConfig(format, output, plugins = []) {
   hasTSChecked = true
 
   const external = ['vue', '@vue/composition-api']
+  if (!isGlobalBuild) {
+    external.push('@vue/devtools-api')
+  }
 
   const nodePlugins = [resolve(), commonjs()]
 
index 910194b713b4cb950f74ea5526799cc331566a50..11b4af5cfa338a6e80ce4f97dc541963157b7ada 100644 (file)
@@ -24,12 +24,9 @@ export function createPinia(): Pinia {
   const pinia: Pinia = {
     install(app: App) {
       pinia._a = localApp = app
-      // pinia._a = app
       app.provide(piniaSymbol, pinia)
       app.config.globalProperties.$pinia = pinia
-      // TODO: write test
-      // only set the app on client for devtools
-      if (__BROWSER__ && IS_CLIENT) {
+      if (IS_CLIENT) {
         // this allows calling useStore() outside of a component setup after
         // installing pinia's plugin
         setActivePinia(pinia)
@@ -53,7 +50,9 @@ export function createPinia(): Pinia {
     state,
   }
 
-  if (IS_CLIENT && __BROWSER__ && __DEV__) {
+  // pinia devtools rely on dev only features so they cannot be forced unless
+  // the dev build of Vue is used
+  if (__DEV__ && IS_CLIENT) {
     pinia.use(devtoolsPlugin)
   }
 
index 87eae11f9691ae30767a9934f3c4b3c01e7e589b..6b1cc2ccd6ec366562bbf73d2e49c19bcc3029a9 100644 (file)
@@ -353,7 +353,8 @@ function buildStoreToUse<
   // created.
   Object.defineProperty(store, '$state', descriptor)
 
-  if (IS_CLIENT && __BROWSER__ && __DEV__) {
+  // add getters for devtools
+  if (__DEV__ && IS_CLIENT) {
     store._getters = Object.keys(getters)
   }
 
@@ -448,13 +449,7 @@ export function defineStore<
     }
 
     // save stores in instances to access them devtools
-    if (
-      __DEV__ &&
-      __BROWSER__ &&
-      IS_CLIENT &&
-      currentInstance &&
-      currentInstance.proxy
-    ) {
+    if (__DEV__ && IS_CLIENT && currentInstance && currentInstance.proxy) {
       const vm = currentInstance.proxy
       const cache = '_pStores' in vm ? vm._pStores! : (vm._pStores = {})
       // @ts-expect-error: still can't cast Store with generics to Store
index 5b4cc5d2671976b8ab381528792e8a7dd090a566..acbb05ea717ab0c9e707193571c4929cb491f94a 100644 (file)
--- a/yarn.lock
+++ b/yarn.lock
     "@vue/compiler-dom" "3.0.11"
     "@vue/shared" "3.0.11"
 
-"@vue/devtools-api@^6.0.0-beta.9":
+"@vue/devtools-api@^6.0.0-beta.10":
   version "6.0.0-beta.10"
   resolved "https://registry.yarnpkg.com/@vue/devtools-api/-/devtools-api-6.0.0-beta.10.tgz#f39da7618cee292e39c7274227c34163e30eb3ca"
   integrity sha512-nktQYRnIFrh4DdXiCBjHnsHOMZXDIVcP9qlm/DMfxmjJMtpMGrSZCOKP8j7kDhObNHyqlicwoGLd+a4hf4x9ww==