2023-10-23 11:19:16 +00:00
import { defu } from 'defu'
2022-08-26 15:47:29 +00:00
import { defineUntypedSchema } from 'untyped'
2022-02-25 19:11:01 +00:00
2022-08-26 15:47:29 +00:00
export default defineUntypedSchema ( {
2022-02-25 19:11:01 +00:00
webpack : {
/ * *
* Nuxt uses ` webpack-bundle-analyzer ` to visualize your bundles and how to optimize them .
*
* Set to ` true ` to enable bundle analysis , or pass an object with options : [ for webpack ] ( https : //github.com/webpack-contrib/webpack-bundle-analyzer#options-for-plugin) or [for vite](https://github.com/btd/rollup-plugin-visualizer#options).
* @example
* ` ` ` js
* analyze : {
* analyzerMode : 'static'
* }
* ` ` `
2023-10-23 11:19:16 +00:00
* @type { boolean | { enabled? : boolean } & typeof import ( 'webpack-bundle-analyzer' ) . BundleAnalyzerPlugin . Options }
2022-02-25 19:11:01 +00:00
* /
analyze : {
2022-09-12 18:22:41 +00:00
$resolve : async ( val , get ) = > {
2023-10-23 11:19:16 +00:00
return defu ( val , await get ( 'build.analyze' ) )
2022-02-25 19:11:01 +00:00
}
} ,
/ * *
* Enable the profiler in webpackbar .
*
* It is normally enabled by CLI argument ` --profile ` .
2022-08-11 21:25:35 +00:00
* @see [ webpackbar ] ( https : //github.com/unjs/webpackbar#profile).
2022-02-25 19:11:01 +00:00
* /
profile : process.argv.includes ( '--profile' ) ,
/ * *
2023-05-25 14:17:17 +00:00
* Enables Common CSS Extraction .
2022-02-25 19:11:01 +00:00
*
2023-05-25 14:17:17 +00:00
* Using [ mini - css - extract - plugin ] ( https : //github.com/webpack-contrib/mini-css-extract-plugin) under the hood, your CSS will be extracted
2022-02-25 19:11:01 +00:00
* into separate files , usually one per component . This allows caching your CSS and
2023-05-25 14:17:17 +00:00
* JavaScript separately .
2022-02-25 19:11:01 +00:00
* @example
* ` ` ` js
* export default {
2022-04-14 15:27:53 +00:00
* webpack : {
2022-02-25 19:11:01 +00:00
* extractCSS : true ,
* // or
* extractCSS : {
* ignoreOrder : true
* }
* }
* }
* ` ` `
*
* If you want to extract all your CSS to a single file , there is a workaround for this .
* However , note that it is not recommended to extract everything into a single file .
* Extracting into multiple CSS files is better for caching and preload isolation . It
* can also improve page performance by downloading and resolving only those resources
* that are needed .
* @example
* ` ` ` js
* export default {
2022-04-14 15:27:53 +00:00
* webpack : {
2022-02-25 19:11:01 +00:00
* extractCSS : true ,
* optimization : {
* splitChunks : {
* cacheGroups : {
* styles : {
* name : 'styles' ,
* test : /\.(css|vue)$/ ,
* chunks : 'all' ,
* enforce : true
* }
* }
* }
* }
* }
* }
* ` ` `
2022-06-13 12:52:27 +00:00
* @type { boolean | typeof import ( 'mini-css-extract-plugin' ) . PluginOptions }
2022-02-25 19:11:01 +00:00
* /
2022-06-13 12:52:27 +00:00
extractCSS : true ,
2022-02-25 19:11:01 +00:00
/ * *
2022-08-11 21:25:35 +00:00
* Enables CSS source map support ( defaults to ` true ` in development ) .
2022-02-25 19:11:01 +00:00
* /
cssSourceMap : {
2022-09-12 18:22:41 +00:00
$resolve : async ( val , get ) = > val ? ? await get ( 'dev' )
2022-02-25 19:11:01 +00:00
} ,
/ * *
* The polyfill library to load to provide URL and URLSearchParams .
*
* Defaults to ` 'url' ` ( [ see package ] ( https : //www.npmjs.com/package/url)).
* /
serverURLPolyfill : 'url' ,
/ * *
* Customize bundle filenames .
*
* To understand a bit more about the use of manifests , take a look at [ this webpack documentation ] ( https : //webpack.js.org/guides/code-splitting/).
* @note Be careful when using non - hashed based filenames in production
* as most browsers will cache the asset and not detect the changes on first load .
*
* This example changes fancy chunk names to numerical ids :
* @example
* ` ` ` js
* filenames : {
* chunk : ( { isDev } ) = > ( isDev ? '[name].js' : '[id].[contenthash].js' )
* }
* ` ` `
2023-06-08 21:50:29 +00:00
* @type {
* Record <
* string ,
* string |
* ( (
* ctx : {
* nuxt : import ( '../src/types/nuxt' ) . Nuxt ,
* options : import ( '../src/types/nuxt' ) . Nuxt [ 'options' ] ,
* name : string ,
* isDev : boolean ,
* isServer : boolean ,
* isClient : boolean ,
* alias : { [ index : string ] : string | false | string [ ] } ,
* transpile : RegExp [ ]
* } ) = > string )
* >
* }
2022-02-25 19:11:01 +00:00
* /
filenames : {
2023-08-08 20:55:29 +00:00
app : ( { isDev } : { isDev : boolean } ) = > isDev ? '[name].js' : '[contenthash:7].js' ,
chunk : ( { isDev } : { isDev : boolean } ) = > isDev ? '[name].js' : '[contenthash:7].js' ,
2022-08-26 15:47:29 +00:00
css : ( { isDev } : { isDev : boolean } ) = > isDev ? '[name].css' : 'css/[contenthash:7].css' ,
img : ( { isDev } : { isDev : boolean } ) = > isDev ? '[path][name].[ext]' : 'img/[name].[contenthash:7].[ext]' ,
font : ( { isDev } : { isDev : boolean } ) = > isDev ? '[path][name].[ext]' : 'fonts/[name].[contenthash:7].[ext]' ,
video : ( { isDev } : { isDev : boolean } ) = > isDev ? '[path][name].[ext]' : 'videos/[name].[contenthash:7].[ext]'
2022-02-25 19:11:01 +00:00
} ,
/ * *
* Customize the options of Nuxt ' s integrated webpack loaders .
* /
loaders : {
2022-09-12 18:22:41 +00:00
$resolve : async ( val , get ) = > {
2022-02-25 19:11:01 +00:00
const styleLoaders = [
'css' , 'cssModules' , 'less' ,
'sass' , 'scss' , 'stylus' , 'vueStyle'
]
for ( const name of styleLoaders ) {
const loader = val [ name ]
if ( loader && loader . sourceMap === undefined ) {
2022-09-12 18:22:41 +00:00
loader . sourceMap = Boolean ( await get ( 'build.cssSourceMap' ) )
2022-02-25 19:11:01 +00:00
}
}
return val
} ,
2023-06-08 21:50:29 +00:00
/ * *
* See https : //github.com/esbuild-kit/esbuild-loader
* @type { Omit < typeof import ( ' esbuild - loader ' ) [ ' LoaderOptions ' ] , ' loader ' > }
2023-08-08 20:55:29 +00:00
* /
2023-06-07 12:50:12 +00:00
esbuild : { } ,
2023-06-08 21:50:29 +00:00
/ * *
* See : https : //github.com/webpack-contrib/file-loader#options
2023-08-08 20:55:29 +00:00
* @type { Omit < typeof import ( ' file - loader ' ) [ ' Options ' ] , ' name ' > }
2023-06-08 21:50:29 +00:00
* @default
* ` ` ` ts
* { esModule : false }
* ` ` `
* /
2022-02-25 19:11:01 +00:00
file : { esModule : false } ,
2023-06-08 21:50:29 +00:00
/ * *
* See : https : //github.com/webpack-contrib/file-loader#options
2023-08-08 20:55:29 +00:00
* @type { Omit < typeof import ( ' file - loader ' ) [ ' Options ' ] , ' name ' > }
2023-06-08 21:50:29 +00:00
* @default
* ` ` ` ts
* { esModule : false , limit : 1000 }
* ` ` `
* /
2022-02-25 19:11:01 +00:00
fontUrl : { esModule : false , limit : 1000 } ,
2023-06-08 21:50:29 +00:00
/ * *
* See : https : //github.com/webpack-contrib/file-loader#options
2023-08-08 20:55:29 +00:00
* @type { Omit < typeof import ( ' file - loader ' ) [ ' Options ' ] , ' name ' > }
2023-06-08 21:50:29 +00:00
* @default
* ` ` ` ts
* { esModule : false , limit : 1000 }
* ` ` `
* /
2022-02-25 19:11:01 +00:00
imgUrl : { esModule : false , limit : 1000 } ,
2023-06-08 21:50:29 +00:00
/ * *
* See : https : //pugjs.org/api/reference.html#options
* @type { typeof import ( 'pug' ) [ 'Options' ] }
* /
2022-02-25 19:11:01 +00:00
pugPlain : { } ,
2023-06-04 22:07:53 +00:00
/ * *
* See [ vue - loader ] ( https : //github.com/vuejs/vue-loader) for available options.
* @type { Partial < typeof import ( ' vue - loader ' ) [ ' VueLoaderOptions ' ] > }
* /
2022-02-25 19:11:01 +00:00
vue : {
transformAssetUrls : {
video : 'src' ,
source : 'src' ,
object : 'src' ,
embed : 'src'
} ,
2022-09-12 18:22:41 +00:00
compilerOptions : { $resolve : async ( val , get ) = > val ? ? ( await get ( 'vue.compilerOptions' ) ) } ,
2023-06-04 23:06:01 +00:00
propsDestructure : { $resolve : async ( val , get ) = > val ? ? Boolean ( await get ( 'vue.propsDestructure' ) ) } ,
2022-02-25 19:11:01 +00:00
} ,
2023-06-08 21:50:29 +00:00
2022-02-25 19:11:01 +00:00
css : {
importLoaders : 0 ,
2022-03-17 17:50:06 +00:00
url : {
2023-12-29 08:47:11 +00:00
filter : ( url : string , _resourcePath : string ) = > url [ 0 ] !== '/'
2022-03-17 17:50:06 +00:00
} ,
2022-02-25 19:11:01 +00:00
esModule : false
} ,
2023-06-08 21:50:29 +00:00
2022-02-25 19:11:01 +00:00
cssModules : {
importLoaders : 0 ,
2022-03-17 17:50:06 +00:00
url : {
2023-12-29 08:47:11 +00:00
filter : ( url : string , _resourcePath : string ) = > url [ 0 ] !== '/'
2022-03-17 17:50:06 +00:00
} ,
2022-02-25 19:11:01 +00:00
esModule : false ,
module s : {
localIdentName : '[local]_[hash:base64:5]'
}
} ,
2023-06-08 21:50:29 +00:00
/ * *
* See : https : //github.com/webpack-contrib/less-loader#options
* /
2022-02-25 19:11:01 +00:00
less : { } ,
2023-06-08 21:50:29 +00:00
/ * *
* See : https : //github.com/webpack-contrib/sass-loader#options
* @type { typeof import ( 'sass-loader' ) [ 'Options' ] }
* @default
* ` ` ` ts
* {
* sassOptions : {
* indentedSyntax : true
* }
* }
* ` ` `
* /
2022-02-25 19:11:01 +00:00
sass : {
sassOptions : {
indentedSyntax : true
}
} ,
2023-06-08 21:50:29 +00:00
/ * *
* See : https : //github.com/webpack-contrib/sass-loader#options
* @type { typeof import ( 'sass-loader' ) [ 'Options' ] }
* /
2022-02-25 19:11:01 +00:00
scss : { } ,
2023-06-08 21:50:29 +00:00
/ * *
* See : https : //github.com/webpack-contrib/stylus-loader#options
* /
2022-02-25 19:11:01 +00:00
stylus : { } ,
2023-06-08 21:50:29 +00:00
2022-02-25 19:11:01 +00:00
vueStyle : { }
} ,
/ * *
* Add webpack plugins .
* @example
* ` ` ` js
* import webpack from 'webpack'
* import { version } from './package.json'
* // ...
* plugins : [
* new webpack . DefinePlugin ( {
* 'process.VERSION' : version
* } )
* ]
* ` ` `
* /
plugins : [ ] ,
/ * *
* Hard - replaces ` typeof process ` , ` typeof window ` and ` typeof document ` to tree - shake bundle .
* /
aggressiveCodeRemoval : false ,
/ * *
* OptimizeCSSAssets plugin options .
*
* Defaults to true when ` extractCSS ` is enabled .
* @see [ css - minimizer - webpack - plugin documentation ] ( https : //github.com/webpack-contrib/css-minimizer-webpack-plugin).
* @type { false | typeof import ( 'css-minimizer-webpack-plugin' ) . BasePluginOptions & typeof import ( 'css-minimizer-webpack-plugin' ) . DefinedDefaultMinimizerAndOptions < any > }
* /
optimizeCSS : {
2022-09-12 18:22:41 +00:00
$resolve : async ( val , get ) = > val ? ? ( await get ( 'build.extractCSS' ) ? { } : false )
2022-02-25 19:11:01 +00:00
} ,
/ * *
* Configure [ webpack optimization ] ( https : //webpack.js.org/configuration/optimization/).
* @type { false | typeof import ( 'webpack' ) . Configuration [ 'optimization' ] }
* /
optimization : {
runtimeChunk : 'single' ,
2022-08-11 21:25:35 +00:00
/** Set minimize to `false` to disable all minimizers. (It is disabled in development by default). */
2022-09-12 18:22:41 +00:00
minimize : { $resolve : async ( val , get ) = > val ? ? ! ( await get ( 'dev' ) ) } ,
2022-02-25 19:11:01 +00:00
/** You can set minimizer to a customized array of plugins. */
minimizer : undefined ,
splitChunks : {
chunks : 'all' ,
automaticNameDelimiter : '/' ,
cacheGroups : { }
}
} ,
2022-10-27 10:36:37 +00:00
2022-02-25 19:11:01 +00:00
/ * *
* Customize PostCSS Loader .
* Same options as https : //github.com/webpack-contrib/postcss-loader#options
2023-04-14 12:53:21 +00:00
* @type { { execute? : boolean , postcssOptions : typeof import ( 'postcss' ) . ProcessOptions , sourceMap? : boolean , implementation? : any } }
2022-02-25 19:11:01 +00:00
* /
postcss : {
postcssOptions : {
config : {
2022-09-12 18:22:41 +00:00
$resolve : async ( val , get ) = > val ? ? ( await get ( 'postcss.config' ) )
2022-02-25 19:11:01 +00:00
} ,
plugins : {
2022-09-12 18:22:41 +00:00
$resolve : async ( val , get ) = > val ? ? ( await get ( 'postcss.plugins' ) )
2022-02-25 19:11:01 +00:00
}
2023-08-08 20:55:29 +00:00
}
2022-02-25 19:11:01 +00:00
} ,
/ * *
* See [ webpack - dev - middleware ] ( https : //github.com/webpack/webpack-dev-middleware) for available options.
* @type { typeof import ( 'webpack-dev-middleware' ) . Options < typeof import ( ' http ' ) .IncomingMessage , typeof import ( ' http ' ) .ServerResponse > }
* /
devMiddleware : {
stats : 'none'
} ,
2022-10-27 10:36:37 +00:00
2022-02-25 19:11:01 +00:00
/ * *
* See [ webpack - hot - middleware ] ( https : //github.com/webpack-contrib/webpack-hot-middleware) for available options.
* @type { typeof import ( 'webpack-hot-middleware' ) . MiddlewareOptions & { client? : typeof import ( 'webpack-hot-middleware' ) . ClientOptions } }
* /
hotMiddleware : { } ,
2022-10-27 10:36:37 +00:00
2022-02-25 19:11:01 +00:00
/ * *
2022-08-11 21:25:35 +00:00
* Set to ` false ` to disable the overlay provided by [ FriendlyErrorsWebpackPlugin ] ( https : //github.com/nuxt/friendly-errors-webpack-plugin).
2022-02-25 19:11:01 +00:00
* /
friendlyErrors : true ,
2022-10-27 10:36:37 +00:00
2022-02-25 19:11:01 +00:00
/ * *
* Filters to hide build warnings .
* @type { Array < ( warn : typeof import ( 'webpack' ) . WebpackError ) = > boolean > }
* /
warningIgnoreFilters : [ ] ,
2023-06-07 19:49:46 +00:00
/ * *
* Configure [ webpack experiments ] ( https : //webpack.js.org/configuration/experiments/)
* @type { false | typeof import ( 'webpack' ) . Configuration [ 'experiments' ] }
* /
experiments : { }
2022-02-25 19:11:01 +00:00
}
2022-08-26 15:47:29 +00:00
} )