From: Eduardo San Martin Morote Date: Thu, 13 May 2021 08:28:48 +0000 (+0200) Subject: build(devtools): externalize devtools X-Git-Tag: v2.0.0-alpha.17~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c813d18c5285f41e37014e89f2e6ecbeaeac4701;p=thirdparty%2Fvuejs%2Fpinia.git build(devtools): externalize devtools --- diff --git a/package.json b/package.json index 5d0d760c..abf4a8e1 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/rollup.config.js b/rollup.config.js index 8a85437d..96c025ed 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -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()] diff --git a/src/createPinia.ts b/src/createPinia.ts index 910194b7..11b4af5c 100644 --- a/src/createPinia.ts +++ b/src/createPinia.ts @@ -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) } diff --git a/src/store.ts b/src/store.ts index 87eae11f..6b1cc2cc 100644 --- a/src/store.ts +++ b/src/store.ts @@ -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 diff --git a/yarn.lock b/yarn.lock index 5b4cc5d2..acbb05ea 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1032,7 +1032,7 @@ "@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==