From c672d8990ad629cd640b6fde9c5bdce2bac275d8 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Tue, 26 Oct 2021 13:49:18 +0100 Subject: [PATCH] feat(vite): pass vue options to vite plugin (#1452) --- packages/kit/src/config/schema/_app.ts | 13 +++++++++---- packages/kit/src/config/schema/build.ts | 3 ++- packages/vite/src/client.ts | 4 ++-- packages/vite/src/server.ts | 2 +- packages/vite/src/vite.ts | 6 +++++- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/packages/kit/src/config/schema/_app.ts b/packages/kit/src/config/schema/_app.ts index 3f410339e0..967cfb580d 100644 --- a/packages/kit/src/config/schema/_app.ts +++ b/packages/kit/src/config/schema/_app.ts @@ -7,16 +7,21 @@ export default { /** Vue.js config */ vue: { /** - * Properties that will be set directly on `Vue.config` for vue@2 and `app.config` for vue@3. + * Properties that will be set directly on `Vue.config` for vue@2. * * @see [vue@2 Documentation](https://vuejs.org/v2/api/#Global-Config) - * @see [vue@3 Documentation](https://v3.vuejs.org/api/application-config.html) * @version 2 */ config: { silent: { $resolve: (val, get) => val ?? !get('dev') }, - performance: { $resolve: (val, get) => val ?? get('dev') } - } + performance: { $resolve: (val, get) => val ?? get('dev') }, + }, + /** + * Options for the Vue compiler that will be passed at build time + * @see [documentation](https://v3.vuejs.org/api/application-config.html) + * @version 3 + */ + compilerOptions: {} }, /** diff --git a/packages/kit/src/config/schema/build.ts b/packages/kit/src/config/schema/build.ts index ce9b4b71bb..e9bf6dfaae 100644 --- a/packages/kit/src/config/schema/build.ts +++ b/packages/kit/src/config/schema/build.ts @@ -228,7 +228,8 @@ export default { source: 'src', object: 'src', embed: 'src' - } + }, + compilerOptions: { $resolve: (val, get) => val ?? get('vue.compilerOptions') }, }, css: { importLoaders: 0, diff --git a/packages/vite/src/client.ts b/packages/vite/src/client.ts index 0b920163db..30dbe49519 100644 --- a/packages/vite/src/client.ts +++ b/packages/vite/src/client.ts @@ -1,7 +1,7 @@ import { resolve } from 'pathe' import * as vite from 'vite' import consola from 'consola' -import vitePlugin from '@vitejs/plugin-vue' +import vuePlugin from '@vitejs/plugin-vue' import viteJsxPlugin from '@vitejs/plugin-vue-jsx' import type { Connect } from 'vite' @@ -39,7 +39,7 @@ export async function buildClient (ctx: ViteBuildContext) { plugins: [ replace({ 'process.env': 'import.meta.env' }), cacheDirPlugin(ctx.nuxt.options.rootDir, 'client'), - vitePlugin(ctx.config.vue), + vuePlugin(ctx.config.vue), viteJsxPlugin() ], server: { diff --git a/packages/vite/src/server.ts b/packages/vite/src/server.ts index 4ae0056059..181e828eae 100644 --- a/packages/vite/src/server.ts +++ b/packages/vite/src/server.ts @@ -68,7 +68,7 @@ export async function buildServer (ctx: ViteBuildContext) { }, plugins: [ cacheDirPlugin(ctx.nuxt.options.rootDir, 'server'), - vuePlugin(), + vuePlugin(ctx.config.vue), viteJsxPlugin() ] } as ViteOptions) diff --git a/packages/vite/src/vite.ts b/packages/vite/src/vite.ts index cb02b4113c..31e46cd413 100644 --- a/packages/vite/src/vite.ts +++ b/packages/vite/src/vite.ts @@ -52,7 +52,11 @@ export async function bundle (nuxt: Nuxt) { } }, base: nuxt.options.build.publicPath, - vue: {}, + // TODO: move to kit schema when it exists + vue: { + isProduction: !nuxt.options.dev, + template: { compilerOptions: nuxt.options.vue.compilerOptions } + }, css: resolveCSSOptions(nuxt), optimizeDeps: { exclude: [],