Nuxt/packages/schema/src/config/vite.ts
Daniel Roe 73ba30fb69
refactor(schema,webpack)!: split out webpack and postcss build options (#2812)
* refactor: split out webpack and postcss build options

* feat(schema): set nuxt3 builder in config

* fix(schema): default postcss config file to false

* chore: update lockfile

* style: remove unused imports

* refactor(webpack): remove (previously disabled) babel config

* refactor: move shared vite options into schema

* fix(schema): omit __NUXT_BASE__ from defaults

* fix: move appDir-dependent options back to vite

* refactor: split out virtual modules

* refactor: extract compile/createDevMiddleware

* refactor: further improvements

* chore: remove `@nuxt/webpack-builder` dependency

* chore: update lockfile

* refactor: move `builder` option to top level

* fix: bind close to watcher instance

* chore: update lockfile

* fix: create portal between postcss & build.postcss.postcssOptions

* fix: remove duplicate

* fix: revert

* fix: use `postcss` directly

* fix: import builder from rootDir

* chore: dedupe webpack install

* test: update fixture to use `builder`

* fix: bind class in pify

Co-authored-by: Pooya Parsa <pyapar@gmail.com>
2022-02-25 20:11:01 +01:00

84 lines
2.0 KiB
TypeScript

import { resolve } from 'pathe'
import { joinURL, withoutLeadingSlash } from 'ufo'
export default {
/**
* Configuration that will be passed directly to Vite.
*
* See https://vitejs.dev/config for more information.
* Please note that not all vite options are supported in Nuxt.
*
* @type {typeof import('vite').InlineConfig}
* @version 3
*/
vite: {
root: {
$resolve: (val, get) => val ?? get('srcDir'),
},
mode: {
$resolve: (val, get) => val ?? get('dev') ? 'development' : 'production',
},
logLevel: 'warn',
define: {
$resolve: (val, get) => ({
'process.dev': get('dev'),
...val || {}
})
},
resolve: {
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'],
},
base: {
$resolve: (val, get) => val ?? get('dev')
? joinURL(get('app').baseURL, get('app').buildAssetsDir)
: '/__NUXT_BASE__/',
},
publicDir: {
$resolve: (val, get) => val ?? resolve(get('srcDir'), get('dir').public),
},
vue: {
isProduction: {
$resolve: (val, get) => val ?? !get('dev'),
},
template: { compilerOptions: {
$resolve: (val, get) => val ?? get('vue').compilerOptions }
},
},
optimizeDeps: {
exclude: {
$resolve: (val, get) => [
...val || [],
...get('build.transpile').filter(i => typeof i === 'string'),
'vue-demi'
],
},
},
esbuild: {
jsxFactory: 'h',
jsxFragment: 'Fragment',
tsconfigRaw: '{}'
},
clearScreen: false,
build: {
assetsDir: {
$resolve: (val, get) => val ?? get('dev') ? withoutLeadingSlash(get('app').buildAssetsDir) : '.',
},
emptyOutDir: false,
},
server: {
fs: {
strict: false,
allow: {
$resolve: (val, get) => [
get('buildDir'),
get('srcDir'),
get('rootDir'),
...get('modulesDir'),
...val ?? []
]
}
}
}
}
}