]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
feat(build): provide more specific warnings for runtime compilation
authorEvan You <yyx990803@gmail.com>
Mon, 20 Apr 2020 19:23:26 +0000 (15:23 -0400)
committerEvan You <yyx990803@gmail.com>
Mon, 20 Apr 2020 19:23:26 +0000 (15:23 -0400)
close #1004

jest.config.js
packages/global.d.ts
packages/runtime-core/src/component.ts
packages/vue/src/index.ts
packages/vue/src/runtime.ts
rollup.config.js

index c88638cb514d1e5cf877e4224e6d19ad23adbe77..5e09ae11841b572ae8b3f7bf1eb42952b263931a 100644 (file)
@@ -5,8 +5,9 @@ module.exports = {
     __TEST__: true,
     __VERSION__: require('./package.json').version,
     __BROWSER__: false,
-    __RUNTIME_COMPILE__: true,
     __GLOBAL__: false,
+    __ESM_BUNDLER__: true,
+    __ESM_BROWSER__: false,
     __NODE_JS__: true,
     __FEATURE_OPTIONS__: true,
     __FEATURE_SUSPENSE__: true
index 11d15fea514150d78ed96680ee18e3e7a8e9ae34..cc72898f2f472c2ae20c71d9664f6f974e4c8eda 100644 (file)
@@ -2,8 +2,9 @@
 declare var __DEV__: boolean
 declare var __TEST__: boolean
 declare var __BROWSER__: boolean
-declare var __RUNTIME_COMPILE__: boolean
 declare var __GLOBAL__: boolean
+declare var __ESM_BUNDLER__: boolean
+declare var __ESM_BROWSER__: boolean
 declare var __NODE_JS__: boolean
 declare var __COMMIT__: string
 declare var __VERSION__: string
index e4893b98e306ee984281e43d6bda2aa227a3563f..eeadd982e4fa416ada8f6399724364e3b808576d 100644 (file)
@@ -451,9 +451,15 @@ function finishComponentSetup(
       /* istanbul ignore if */
       if (!compile && Component.template) {
         warn(
-          `Component provides template but the build of Vue you are running ` +
-            `does not support runtime template compilation. Either use the ` +
-            `full build or pre-compile the template using Vue CLI.`
+          `Component provided template option but ` +
+            `runtime compilation is not supported in this build of Vue.` +
+            (__ESM_BUNDLER__
+              ? ` Configure your bundler to alias "vue" to "vue/dist/vue.esm-bundler.js".`
+              : __ESM_BROWSER__
+                ? ` Use "vue.esm-browser.js" instead.`
+                : __GLOBAL__
+                  ? ` Use "vue.global.js" instead.`
+                  : ``) /* should not happen */
         )
       } else {
         warn(`Component is missing template or render function.`)
index 056fcc90cc03e53baf401de79155ef0ce10509d3..c15946af76c2ecccc96efe87065c77c6368f2739 100644 (file)
@@ -1,5 +1,6 @@
 // This entry is the "full-build" that includes both the runtime
 // and the compiler, and supports on-the-fly compilation of the template option.
+import './devCheck'
 import { compile, CompilerOptions, CompilerError } from '@vue/compiler-dom'
 import { registerRuntimeCompiler, RenderFunction, warn } from '@vue/runtime-dom'
 import * as runtimeDom from '@vue/runtime-dom'
@@ -72,5 +73,3 @@ registerRuntimeCompiler(compileToFunction)
 
 export { compileToFunction as compile }
 export * from '@vue/runtime-dom'
-
-import './devCheck'
index b6bbe504172ce325ee5f7a90f369c4e8dbf7636e..fdbdd153d27be03cf09afd47602dd26336519ee8 100644 (file)
@@ -1,6 +1,21 @@
 // This entry exports the runtime only, and is built as
 // `dist/vue.esm-bundler.js` which is used by default for bundlers.
+import './devCheck'
+import { warn } from '@vue/runtime-dom'
 
 export * from '@vue/runtime-dom'
 
-import './devCheck'
+export const compile = () => {
+  if (__DEV__) {
+    warn(
+      `Runtime compilation is not supported in this build of Vue.` +
+        (__ESM_BUNDLER__
+          ? ` Configure your bundler to alias "vue" to "vue/dist/vue.esm-bundler.js".`
+          : __ESM_BROWSER__
+            ? ` Use "vue.esm-browser.js" instead.`
+            : __GLOBAL__
+              ? ` Use "vue.global.js" instead.`
+              : ``) /* should not happen */
+    )
+  }
+}
index c48021c55d87a67af3bf0e614618826d8fd7084c..152876056a2ce3d804d8a36dc602376c3df84087 100644 (file)
@@ -141,6 +141,7 @@ function createConfig(format, output, plugins = []) {
       createReplacePlugin(
         isProductionBuild,
         isBundlerESMBuild,
+        isBrowserESMBuild,
         // isBrowserBuild?
         (isGlobalBuild || isBrowserESMBuild || isBundlerESMBuild) &&
           !packageOptions.enableNonBrowserBranches,
@@ -162,6 +163,7 @@ function createConfig(format, output, plugins = []) {
 function createReplacePlugin(
   isProduction,
   isBundlerESMBuild,
+  isBrowserESMBuild,
   isBrowserBuild,
   isGlobalBuild,
   isNodeBuild
@@ -179,6 +181,8 @@ function createReplacePlugin(
     // If the build is expected to run directly in the browser (global / esm builds)
     __BROWSER__: isBrowserBuild,
     __GLOBAL__: isGlobalBuild,
+    __ESM_BUNDLER__: isBundlerESMBuild,
+    __ESM_BROWSER__: isBrowserESMBuild,
     // is targeting Node (SSR)?
     __NODE_JS__: isNodeBuild,
     __FEATURE_OPTIONS__: true,