Skip to content

Commit cd11f41

Browse files
committed
build: externalize @vue/devtools-api in bundler build
1 parent ab45fe3 commit cd11f41

File tree

5 files changed

+14
-8
lines changed

5 files changed

+14
-8
lines changed

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
"tags": "vetur/tags.json",
6161
"attributes": "vetur/attributes.json"
6262
},
63+
"dependencies": {
64+
"@vue/devtools-api": "^6.0.0-beta.10"
65+
},
6366
"devDependencies": {
6467
"@microsoft/api-extractor": "7.8.1",
6568
"@rollup/plugin-alias": "^3.1.2",
@@ -72,7 +75,6 @@
7275
"@types/webpack": "^5.28.0",
7376
"@types/webpack-env": "^1.16.0",
7477
"@vue/compiler-sfc": "^3.0.7",
75-
"@vue/devtools-api": "^6.0.0-beta.9",
7678
"@vue/server-renderer": "^3.0.7",
7779
"@vue/test-utils": "^2.0.0-rc.3",
7880
"axios": "^0.21.1",

rollup.config.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ function createConfig(format, output, plugins = []) {
6666
output.externalLiveBindings = false
6767
output.globals = {
6868
vue: 'Vue',
69-
'@vue/devtools-api': 'VueDevtoolsApi',
69+
// devtools are not global in iife
70+
// '@vue/devtools-api': 'VueDevtoolsApi',
7071
}
7172

7273
const isProductionBuild = /\.prod\.js$/.test(output.file)
@@ -97,10 +98,10 @@ function createConfig(format, output, plugins = []) {
9798
// during a single build.
9899
hasTSChecked = true
99100

100-
const external = [
101-
'vue',
102-
// '@vue/devtools-api',
103-
]
101+
const external = ['vue']
102+
if (!isGlobalBuild) {
103+
external.push('@vue/devtools-api')
104+
}
104105

105106
const nodePlugins = [resolve(), commonjs()]
106107

src/RouterLink.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { isSameRouteLocationParams, isSameRouteRecord } from './location'
1717
import { routerKey, routeLocationKey } from './injectionSymbols'
1818
import { RouteRecord } from './matcher/types'
1919
import { NavigationFailure } from './errors'
20+
import { isBrowser } from './utils'
2021

2122
export interface RouterLinkOptions {
2223
/**
@@ -166,7 +167,8 @@ export const RouterLinkImpl = /*#__PURE__*/ defineComponent({
166167
)]: link.isExactActive,
167168
}))
168169

169-
if ((__DEV__ || __FEATURE_PROD_DEVTOOLS__) && __BROWSER__) {
170+
// devtools only
171+
if ((__DEV__ || __FEATURE_PROD_DEVTOOLS__) && isBrowser) {
170172
const instance = getCurrentInstance()
171173
watchEffect(
172174
() => {

src/errors.ts

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ export function createRouterError<E extends RouterError>(
114114
type: E['type'],
115115
params: Omit<E, 'type' | keyof Error>
116116
): E {
117+
// keep full error messages in cjs versions
117118
if (__DEV__ || !__BROWSER__) {
118119
return assign(
119120
new Error(ErrorTypeMessages[type](params as any)),

src/router.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@ export function createRouter(options: RouterOptions): Router {
11471147
unmountApp()
11481148
}
11491149

1150-
if ((__DEV__ || __FEATURE_PROD_DEVTOOLS__) && __BROWSER__) {
1150+
if ((__DEV__ || __FEATURE_PROD_DEVTOOLS__) && isBrowser) {
11511151
addDevtools(app, router, matcher)
11521152
}
11531153
},

0 commit comments

Comments
 (0)