feat(config): support configuring runtime compiler via app.config.compilerOptions

- `config.isCustomElement` is deprecated - use `app.config.compilerOptions.isCustomElement` instead.
This commit is contained in:
Evan You
2021-04-26 11:46:29 -04:00
parent b047a0864c
commit 091e6d67bf
4 changed files with 85 additions and 18 deletions

View File

@@ -58,7 +58,7 @@ export const createApp = ((...args) => {
if (__DEV__) {
injectNativeTagCheck(app)
injectCustomElementCheck(app)
injectCompilerOptionsCheck(app)
}
const { mount } = app
@@ -106,7 +106,7 @@ export const createSSRApp = ((...args) => {
if (__DEV__) {
injectNativeTagCheck(app)
injectCustomElementCheck(app)
injectCompilerOptionsCheck(app)
}
const { mount } = app
@@ -130,21 +130,40 @@ function injectNativeTagCheck(app: App) {
}
// dev only
function injectCustomElementCheck(app: App) {
function injectCompilerOptionsCheck(app: App) {
if (isRuntimeOnly()) {
const value = app.config.isCustomElement
const isCustomElement = app.config.isCustomElement
Object.defineProperty(app.config, 'isCustomElement', {
get() {
return value
return isCustomElement
},
set() {
warn(
`The \`isCustomElement\` config option is only respected when using the runtime compiler.` +
`If you are using the runtime-only build, \`isCustomElement\` must be passed to \`@vue/compiler-dom\` in the build setup instead` +
`- for example, via the \`compilerOptions\` option in vue-loader: https://vue-loader.vuejs.org/options.html#compileroptions.`
`The \`isCustomElement\` config option is deprecated. Use ` +
`\`compilerOptions.isCustomElement\` instead.`
)
}
})
const compilerOptions = app.config.compilerOptions
const msg =
`The \`compilerOptions\` config option is only respected when using ` +
`a build of Vue.js that includes the runtime compiler (aka "full build"). ` +
`Since you are using the runtime-only build, \`compilerOptions\` ` +
`must be passed to \`@vue/compiler-dom\` in the build setup instead.\n` +
`- For vue-loader: pass it via vue-loader's \`compilerOptions\` loader option.\n` +
`- For vue-cli: see https://cli.vuejs.org/guide/webpack.html#modifying-options-of-a-loader\n` +
`- For vite: pass it via @vitejs/plugin-vue options. See https://github.com/vitejs/vite/tree/main/packages/plugin-vue#example-for-passing-options-to-vuecompiler-dom`
Object.defineProperty(app.config, 'compilerOptions', {
get() {
warn(msg)
return compilerOptions
},
set() {
warn(msg)
}
})
}
}