feat(vite): pass vue options to vite plugin (#1452)

This commit is contained in:
Daniel Roe 2021-10-26 13:49:18 +01:00 committed by GitHub
parent 3761b064d0
commit c672d8990a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 9 deletions

View File

@ -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: {}
},
/**

View File

@ -228,7 +228,8 @@ export default {
source: 'src',
object: 'src',
embed: 'src'
}
},
compilerOptions: { $resolve: (val, get) => val ?? get('vue.compilerOptions') },
},
css: {
importLoaders: 0,

View File

@ -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: {

View File

@ -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)

View File

@ -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: [],