Skip to content

Commit e954ba2

Browse files
committed
feat(build): provide more specific warnings for runtime compilation
close #1004
1 parent 171cfa4 commit e954ba2

File tree

6 files changed

+34
-8
lines changed

6 files changed

+34
-8
lines changed

jest.config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ module.exports = {
55
__TEST__: true,
66
__VERSION__: require('./package.json').version,
77
__BROWSER__: false,
8-
__RUNTIME_COMPILE__: true,
98
__GLOBAL__: false,
9+
__ESM_BUNDLER__: true,
10+
__ESM_BROWSER__: false,
1011
__NODE_JS__: true,
1112
__FEATURE_OPTIONS__: true,
1213
__FEATURE_SUSPENSE__: true

packages/global.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
declare var __DEV__: boolean
33
declare var __TEST__: boolean
44
declare var __BROWSER__: boolean
5-
declare var __RUNTIME_COMPILE__: boolean
65
declare var __GLOBAL__: boolean
6+
declare var __ESM_BUNDLER__: boolean
7+
declare var __ESM_BROWSER__: boolean
78
declare var __NODE_JS__: boolean
89
declare var __COMMIT__: string
910
declare var __VERSION__: string

packages/runtime-core/src/component.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -451,9 +451,15 @@ function finishComponentSetup(
451451
/* istanbul ignore if */
452452
if (!compile && Component.template) {
453453
warn(
454-
`Component provides template but the build of Vue you are running ` +
455-
`does not support runtime template compilation. Either use the ` +
456-
`full build or pre-compile the template using Vue CLI.`
454+
`Component provided template option but ` +
455+
`runtime compilation is not supported in this build of Vue.` +
456+
(__ESM_BUNDLER__
457+
? ` Configure your bundler to alias "vue" to "vue/dist/vue.esm-bundler.js".`
458+
: __ESM_BROWSER__
459+
? ` Use "vue.esm-browser.js" instead.`
460+
: __GLOBAL__
461+
? ` Use "vue.global.js" instead.`
462+
: ``) /* should not happen */
457463
)
458464
} else {
459465
warn(`Component is missing template or render function.`)

packages/vue/src/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// This entry is the "full-build" that includes both the runtime
22
// and the compiler, and supports on-the-fly compilation of the template option.
3+
import './devCheck'
34
import { compile, CompilerOptions, CompilerError } from '@vue/compiler-dom'
45
import { registerRuntimeCompiler, RenderFunction, warn } from '@vue/runtime-dom'
56
import * as runtimeDom from '@vue/runtime-dom'
@@ -72,5 +73,3 @@ registerRuntimeCompiler(compileToFunction)
7273

7374
export { compileToFunction as compile }
7475
export * from '@vue/runtime-dom'
75-
76-
import './devCheck'

packages/vue/src/runtime.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
// This entry exports the runtime only, and is built as
22
// `dist/vue.esm-bundler.js` which is used by default for bundlers.
3+
import './devCheck'
4+
import { warn } from '@vue/runtime-dom'
35

46
export * from '@vue/runtime-dom'
57

6-
import './devCheck'
8+
export const compile = () => {
9+
if (__DEV__) {
10+
warn(
11+
`Runtime compilation is not supported in this build of Vue.` +
12+
(__ESM_BUNDLER__
13+
? ` Configure your bundler to alias "vue" to "vue/dist/vue.esm-bundler.js".`
14+
: __ESM_BROWSER__
15+
? ` Use "vue.esm-browser.js" instead.`
16+
: __GLOBAL__
17+
? ` Use "vue.global.js" instead.`
18+
: ``) /* should not happen */
19+
)
20+
}
21+
}

rollup.config.js

+4
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ function createConfig(format, output, plugins = []) {
141141
createReplacePlugin(
142142
isProductionBuild,
143143
isBundlerESMBuild,
144+
isBrowserESMBuild,
144145
// isBrowserBuild?
145146
(isGlobalBuild || isBrowserESMBuild || isBundlerESMBuild) &&
146147
!packageOptions.enableNonBrowserBranches,
@@ -162,6 +163,7 @@ function createConfig(format, output, plugins = []) {
162163
function createReplacePlugin(
163164
isProduction,
164165
isBundlerESMBuild,
166+
isBrowserESMBuild,
165167
isBrowserBuild,
166168
isGlobalBuild,
167169
isNodeBuild
@@ -179,6 +181,8 @@ function createReplacePlugin(
179181
// If the build is expected to run directly in the browser (global / esm builds)
180182
__BROWSER__: isBrowserBuild,
181183
__GLOBAL__: isGlobalBuild,
184+
__ESM_BUNDLER__: isBundlerESMBuild,
185+
__ESM_BROWSER__: isBrowserESMBuild,
182186
// is targeting Node (SSR)?
183187
__NODE_JS__: isNodeBuild,
184188
__FEATURE_OPTIONS__: true,

0 commit comments

Comments
 (0)