Skip to content

Commit

Permalink
build: externalize @vue/devtools-api in bundler build
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed May 13, 2021
1 parent ab45fe3 commit cd11f41
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -60,6 +60,9 @@
"tags": "vetur/tags.json",
"attributes": "vetur/attributes.json"
},
"dependencies": {
"@vue/devtools-api": "^6.0.0-beta.10"
},
"devDependencies": {
"@microsoft/api-extractor": "7.8.1",
"@rollup/plugin-alias": "^3.1.2",
Expand All @@ -72,7 +75,6 @@
"@types/webpack": "^5.28.0",
"@types/webpack-env": "^1.16.0",
"@vue/compiler-sfc": "^3.0.7",
"@vue/devtools-api": "^6.0.0-beta.9",
"@vue/server-renderer": "^3.0.7",
"@vue/test-utils": "^2.0.0-rc.3",
"axios": "^0.21.1",
Expand Down
11 changes: 6 additions & 5 deletions rollup.config.js
Expand Up @@ -66,7 +66,8 @@ function createConfig(format, output, plugins = []) {
output.externalLiveBindings = false
output.globals = {
vue: 'Vue',
'@vue/devtools-api': 'VueDevtoolsApi',
// devtools are not global in iife
// '@vue/devtools-api': 'VueDevtoolsApi',
}

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

const external = [
'vue',
// '@vue/devtools-api',
]
const external = ['vue']
if (!isGlobalBuild) {
external.push('@vue/devtools-api')
}

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

Expand Down
4 changes: 3 additions & 1 deletion src/RouterLink.ts
Expand Up @@ -17,6 +17,7 @@ import { isSameRouteLocationParams, isSameRouteRecord } from './location'
import { routerKey, routeLocationKey } from './injectionSymbols'
import { RouteRecord } from './matcher/types'
import { NavigationFailure } from './errors'
import { isBrowser } from './utils'

export interface RouterLinkOptions {
/**
Expand Down Expand Up @@ -166,7 +167,8 @@ export const RouterLinkImpl = /*#__PURE__*/ defineComponent({
)]: link.isExactActive,
}))

if ((__DEV__ || __FEATURE_PROD_DEVTOOLS__) && __BROWSER__) {
// devtools only
if ((__DEV__ || __FEATURE_PROD_DEVTOOLS__) && isBrowser) {
const instance = getCurrentInstance()
watchEffect(
() => {
Expand Down
1 change: 1 addition & 0 deletions src/errors.ts
Expand Up @@ -114,6 +114,7 @@ export function createRouterError<E extends RouterError>(
type: E['type'],
params: Omit<E, 'type' | keyof Error>
): E {
// keep full error messages in cjs versions
if (__DEV__ || !__BROWSER__) {
return assign(
new Error(ErrorTypeMessages[type](params as any)),
Expand Down
2 changes: 1 addition & 1 deletion src/router.ts
Expand Up @@ -1147,7 +1147,7 @@ export function createRouter(options: RouterOptions): Router {
unmountApp()
}

if ((__DEV__ || __FEATURE_PROD_DEVTOOLS__) && __BROWSER__) {
if ((__DEV__ || __FEATURE_PROD_DEVTOOLS__) && isBrowser) {
addDevtools(app, router, matcher)
}
},
Expand Down

0 comments on commit cd11f41

Please sign in to comment.