mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-13 09:33:54 +00:00
feat(schema): support setting hidden
sourcemaps (#22787)
This commit is contained in:
parent
6f7d86be78
commit
23723305da
@ -208,16 +208,16 @@ export default defineNuxtModule<ComponentsOptions>({
|
|||||||
config.plugins = config.plugins || []
|
config.plugins = config.plugins || []
|
||||||
if (nuxt.options.experimental.treeshakeClientOnly && isServer) {
|
if (nuxt.options.experimental.treeshakeClientOnly && isServer) {
|
||||||
config.plugins.push(TreeShakeTemplatePlugin.vite({
|
config.plugins.push(TreeShakeTemplatePlugin.vite({
|
||||||
sourcemap: nuxt.options.sourcemap[mode],
|
sourcemap: !!nuxt.options.sourcemap[mode],
|
||||||
getComponents
|
getComponents
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
config.plugins.push(clientFallbackAutoIdPlugin.vite({
|
config.plugins.push(clientFallbackAutoIdPlugin.vite({
|
||||||
sourcemap: nuxt.options.sourcemap[mode],
|
sourcemap: !!nuxt.options.sourcemap[mode],
|
||||||
rootDir: nuxt.options.rootDir
|
rootDir: nuxt.options.rootDir
|
||||||
}))
|
}))
|
||||||
config.plugins.push(loaderPlugin.vite({
|
config.plugins.push(loaderPlugin.vite({
|
||||||
sourcemap: nuxt.options.sourcemap[mode],
|
sourcemap: !!nuxt.options.sourcemap[mode],
|
||||||
getComponents,
|
getComponents,
|
||||||
mode,
|
mode,
|
||||||
transform: typeof nuxt.options.components === 'object' && !Array.isArray(nuxt.options.components) ? nuxt.options.components.transform : undefined,
|
transform: typeof nuxt.options.components === 'object' && !Array.isArray(nuxt.options.components) ? nuxt.options.components.transform : undefined,
|
||||||
@ -252,16 +252,16 @@ export default defineNuxtModule<ComponentsOptions>({
|
|||||||
config.plugins = config.plugins || []
|
config.plugins = config.plugins || []
|
||||||
if (nuxt.options.experimental.treeshakeClientOnly && mode === 'server') {
|
if (nuxt.options.experimental.treeshakeClientOnly && mode === 'server') {
|
||||||
config.plugins.push(TreeShakeTemplatePlugin.webpack({
|
config.plugins.push(TreeShakeTemplatePlugin.webpack({
|
||||||
sourcemap: nuxt.options.sourcemap[mode],
|
sourcemap: !!nuxt.options.sourcemap[mode],
|
||||||
getComponents
|
getComponents
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
config.plugins.push(clientFallbackAutoIdPlugin.webpack({
|
config.plugins.push(clientFallbackAutoIdPlugin.webpack({
|
||||||
sourcemap: nuxt.options.sourcemap[mode],
|
sourcemap: !!nuxt.options.sourcemap[mode],
|
||||||
rootDir: nuxt.options.rootDir
|
rootDir: nuxt.options.rootDir
|
||||||
}))
|
}))
|
||||||
config.plugins.push(loaderPlugin.webpack({
|
config.plugins.push(loaderPlugin.webpack({
|
||||||
sourcemap: nuxt.options.sourcemap[mode],
|
sourcemap: !!nuxt.options.sourcemap[mode],
|
||||||
getComponents,
|
getComponents,
|
||||||
mode,
|
mode,
|
||||||
transform: typeof nuxt.options.components === 'object' && !Array.isArray(nuxt.options.components) ? nuxt.options.components.transform : undefined,
|
transform: typeof nuxt.options.components === 'object' && !Array.isArray(nuxt.options.components) ? nuxt.options.components.transform : undefined,
|
||||||
|
@ -94,14 +94,14 @@ async function initNuxt (nuxt: Nuxt) {
|
|||||||
if (nuxt.options.experimental.localLayerAliases) {
|
if (nuxt.options.experimental.localLayerAliases) {
|
||||||
// Add layer aliasing support for ~, ~~, @ and @@ aliases
|
// Add layer aliasing support for ~, ~~, @ and @@ aliases
|
||||||
addVitePlugin(() => LayerAliasingPlugin.vite({
|
addVitePlugin(() => LayerAliasingPlugin.vite({
|
||||||
sourcemap: nuxt.options.sourcemap.server || nuxt.options.sourcemap.client,
|
sourcemap: !!nuxt.options.sourcemap.server || !!nuxt.options.sourcemap.client,
|
||||||
dev: nuxt.options.dev,
|
dev: nuxt.options.dev,
|
||||||
root: nuxt.options.srcDir,
|
root: nuxt.options.srcDir,
|
||||||
// skip top-level layer (user's project) as the aliases will already be correctly resolved
|
// skip top-level layer (user's project) as the aliases will already be correctly resolved
|
||||||
layers: nuxt.options._layers.slice(1)
|
layers: nuxt.options._layers.slice(1)
|
||||||
}))
|
}))
|
||||||
addWebpackPlugin(() => LayerAliasingPlugin.webpack({
|
addWebpackPlugin(() => LayerAliasingPlugin.webpack({
|
||||||
sourcemap: nuxt.options.sourcemap.server || nuxt.options.sourcemap.client,
|
sourcemap: !!nuxt.options.sourcemap.server || !!nuxt.options.sourcemap.client,
|
||||||
dev: nuxt.options.dev,
|
dev: nuxt.options.dev,
|
||||||
root: nuxt.options.srcDir,
|
root: nuxt.options.srcDir,
|
||||||
// skip top-level layer (user's project) as the aliases will already be correctly resolved
|
// skip top-level layer (user's project) as the aliases will already be correctly resolved
|
||||||
@ -113,7 +113,7 @@ async function initNuxt (nuxt: Nuxt) {
|
|||||||
nuxt.hook('modules:done', () => {
|
nuxt.hook('modules:done', () => {
|
||||||
// Add unctx transform
|
// Add unctx transform
|
||||||
const options = {
|
const options = {
|
||||||
sourcemap: nuxt.options.sourcemap.server || nuxt.options.sourcemap.client,
|
sourcemap: !!nuxt.options.sourcemap.server || !!nuxt.options.sourcemap.client,
|
||||||
transformerOptions: nuxt.options.optimization.asyncTransforms
|
transformerOptions: nuxt.options.optimization.asyncTransforms
|
||||||
}
|
}
|
||||||
addVitePlugin(() => UnctxTransformPlugin.vite(options))
|
addVitePlugin(() => UnctxTransformPlugin.vite(options))
|
||||||
@ -121,7 +121,7 @@ async function initNuxt (nuxt: Nuxt) {
|
|||||||
|
|
||||||
// Add composable tree-shaking optimisations
|
// Add composable tree-shaking optimisations
|
||||||
const serverTreeShakeOptions: TreeShakeComposablesPluginOptions = {
|
const serverTreeShakeOptions: TreeShakeComposablesPluginOptions = {
|
||||||
sourcemap: nuxt.options.sourcemap.server,
|
sourcemap: !!nuxt.options.sourcemap.server,
|
||||||
composables: nuxt.options.optimization.treeShake.composables.server
|
composables: nuxt.options.optimization.treeShake.composables.server
|
||||||
}
|
}
|
||||||
if (Object.keys(serverTreeShakeOptions.composables).length) {
|
if (Object.keys(serverTreeShakeOptions.composables).length) {
|
||||||
@ -129,7 +129,7 @@ async function initNuxt (nuxt: Nuxt) {
|
|||||||
addWebpackPlugin(() => TreeShakeComposablesPlugin.webpack(serverTreeShakeOptions), { client: false })
|
addWebpackPlugin(() => TreeShakeComposablesPlugin.webpack(serverTreeShakeOptions), { client: false })
|
||||||
}
|
}
|
||||||
const clientTreeShakeOptions: TreeShakeComposablesPluginOptions = {
|
const clientTreeShakeOptions: TreeShakeComposablesPluginOptions = {
|
||||||
sourcemap: nuxt.options.sourcemap.client,
|
sourcemap: !!nuxt.options.sourcemap.client,
|
||||||
composables: nuxt.options.optimization.treeShake.composables.client
|
composables: nuxt.options.optimization.treeShake.composables.client
|
||||||
}
|
}
|
||||||
if (Object.keys(clientTreeShakeOptions.composables).length) {
|
if (Object.keys(clientTreeShakeOptions.composables).length) {
|
||||||
@ -140,8 +140,8 @@ async function initNuxt (nuxt: Nuxt) {
|
|||||||
|
|
||||||
if (!nuxt.options.dev) {
|
if (!nuxt.options.dev) {
|
||||||
// DevOnly component tree-shaking - build time only
|
// DevOnly component tree-shaking - build time only
|
||||||
addVitePlugin(() => DevOnlyPlugin.vite({ sourcemap: nuxt.options.sourcemap.server || nuxt.options.sourcemap.client }))
|
addVitePlugin(() => DevOnlyPlugin.vite({ sourcemap: !!nuxt.options.sourcemap.server || !!nuxt.options.sourcemap.client }))
|
||||||
addWebpackPlugin(() => DevOnlyPlugin.webpack({ sourcemap: nuxt.options.sourcemap.server || nuxt.options.sourcemap.client }))
|
addWebpackPlugin(() => DevOnlyPlugin.webpack({ sourcemap: !!nuxt.options.sourcemap.server || !!nuxt.options.sourcemap.client }))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transform initial composable call within `<script setup>` to preserve context
|
// Transform initial composable call within `<script setup>` to preserve context
|
||||||
|
@ -82,8 +82,8 @@ export default defineNuxtModule<Partial<ImportsOptions>>({
|
|||||||
nuxt.options.alias['#imports'] = join(nuxt.options.buildDir, 'imports')
|
nuxt.options.alias['#imports'] = join(nuxt.options.buildDir, 'imports')
|
||||||
|
|
||||||
// Transform to inject imports in production mode
|
// Transform to inject imports in production mode
|
||||||
addVitePlugin(() => TransformPlugin.vite({ ctx, options, sourcemap: nuxt.options.sourcemap.server || nuxt.options.sourcemap.client }))
|
addVitePlugin(() => TransformPlugin.vite({ ctx, options, sourcemap: !!nuxt.options.sourcemap.server || !!nuxt.options.sourcemap.client }))
|
||||||
addWebpackPlugin(() => TransformPlugin.webpack({ ctx, options, sourcemap: nuxt.options.sourcemap.server || nuxt.options.sourcemap.client }))
|
addWebpackPlugin(() => TransformPlugin.webpack({ ctx, options, sourcemap: !!nuxt.options.sourcemap.server || !!nuxt.options.sourcemap.client }))
|
||||||
|
|
||||||
const priorities = nuxt.options._layers.map((layer, i) => [layer.config.srcDir, -i] as const).sort(([a], [b]) => b.length - a.length)
|
const priorities = nuxt.options._layers.map((layer, i) => [layer.config.srcDir, -i] as const).sort(([a], [b]) => b.length - a.length)
|
||||||
|
|
||||||
|
@ -308,7 +308,7 @@ export default defineNuxtModule({
|
|||||||
// Extract macros from pages
|
// Extract macros from pages
|
||||||
const pageMetaOptions: PageMetaPluginOptions = {
|
const pageMetaOptions: PageMetaPluginOptions = {
|
||||||
dev: nuxt.options.dev,
|
dev: nuxt.options.dev,
|
||||||
sourcemap: nuxt.options.sourcemap.server || nuxt.options.sourcemap.client
|
sourcemap: !!nuxt.options.sourcemap.server || !!nuxt.options.sourcemap.client
|
||||||
}
|
}
|
||||||
nuxt.hook('modules:done', () => {
|
nuxt.hook('modules:done', () => {
|
||||||
addVitePlugin(() => PageMetaPlugin.vite(pageMetaOptions))
|
addVitePlugin(() => PageMetaPlugin.vite(pageMetaOptions))
|
||||||
|
@ -25,7 +25,7 @@ export default defineUntypedSchema({
|
|||||||
/**
|
/**
|
||||||
* Whether to generate sourcemaps.
|
* Whether to generate sourcemaps.
|
||||||
*
|
*
|
||||||
* @type {boolean | { server?: boolean, client?: boolean }}
|
* @type {boolean | { server?: boolean | 'hidden', client?: boolean | 'hidden' }}
|
||||||
*/
|
*/
|
||||||
sourcemap: {
|
sourcemap: {
|
||||||
$resolve: async (val, get) => {
|
$resolve: async (val, get) => {
|
||||||
|
@ -35,7 +35,7 @@ export async function buildClient (ctx: ViteBuildContext) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
css: {
|
css: {
|
||||||
devSourcemap: ctx.nuxt.options.sourcemap.client
|
devSourcemap: !!ctx.nuxt.options.sourcemap.client
|
||||||
},
|
},
|
||||||
define: {
|
define: {
|
||||||
'process.env.NODE_ENV': JSON.stringify(ctx.config.mode),
|
'process.env.NODE_ENV': JSON.stringify(ctx.config.mode),
|
||||||
@ -78,11 +78,11 @@ export async function buildClient (ctx: ViteBuildContext) {
|
|||||||
buildAssetsURL: joinURL(ctx.nuxt.options.app.baseURL, ctx.nuxt.options.app.buildAssetsDir)
|
buildAssetsURL: joinURL(ctx.nuxt.options.app.baseURL, ctx.nuxt.options.app.buildAssetsDir)
|
||||||
}),
|
}),
|
||||||
runtimePathsPlugin({
|
runtimePathsPlugin({
|
||||||
sourcemap: ctx.nuxt.options.sourcemap.client
|
sourcemap: !!ctx.nuxt.options.sourcemap.client
|
||||||
}),
|
}),
|
||||||
viteNodePlugin(ctx),
|
viteNodePlugin(ctx),
|
||||||
pureAnnotationsPlugin.vite({
|
pureAnnotationsPlugin.vite({
|
||||||
sourcemap: ctx.nuxt.options.sourcemap.client,
|
sourcemap: !!ctx.nuxt.options.sourcemap.client,
|
||||||
functions: ['defineComponent', 'defineAsyncComponent', 'defineNuxtLink', 'createClientOnly', 'defineNuxtPlugin', 'defineNuxtRouteMiddleware', 'defineNuxtComponent', 'useRuntimeConfig', 'defineRouteRules']
|
functions: ['defineComponent', 'defineAsyncComponent', 'defineNuxtLink', 'createClientOnly', 'defineNuxtPlugin', 'defineNuxtRouteMiddleware', 'defineNuxtComponent', 'useRuntimeConfig', 'defineRouteRules']
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
@ -102,7 +102,7 @@ export async function buildClient (ctx: ViteBuildContext) {
|
|||||||
|
|
||||||
// Emit chunk errors if the user has opted in to `experimental.emitRouteChunkError`
|
// Emit chunk errors if the user has opted in to `experimental.emitRouteChunkError`
|
||||||
if (ctx.nuxt.options.experimental.emitRouteChunkError) {
|
if (ctx.nuxt.options.experimental.emitRouteChunkError) {
|
||||||
clientConfig.plugins!.push(chunkErrorPlugin({ sourcemap: ctx.nuxt.options.sourcemap.client }))
|
clientConfig.plugins!.push(chunkErrorPlugin({ sourcemap: !!ctx.nuxt.options.sourcemap.client }))
|
||||||
}
|
}
|
||||||
|
|
||||||
// We want to respect users' own rollup output options
|
// We want to respect users' own rollup output options
|
||||||
@ -135,7 +135,7 @@ export async function buildClient (ctx: ViteBuildContext) {
|
|||||||
|
|
||||||
// Add type checking client panel
|
// Add type checking client panel
|
||||||
if (ctx.nuxt.options.typescript.typeCheck && ctx.nuxt.options.dev) {
|
if (ctx.nuxt.options.typescript.typeCheck && ctx.nuxt.options.dev) {
|
||||||
clientConfig.plugins!.push(typeCheckPlugin({ sourcemap: ctx.nuxt.options.sourcemap.client }))
|
clientConfig.plugins!.push(typeCheckPlugin({ sourcemap: !!ctx.nuxt.options.sourcemap.client }))
|
||||||
}
|
}
|
||||||
|
|
||||||
await ctx.nuxt.callHook('vite:extendConfig', clientConfig, { isClient: true, isServer: false })
|
await ctx.nuxt.callHook('vite:extendConfig', clientConfig, { isClient: true, isServer: false })
|
||||||
|
@ -37,7 +37,7 @@ export async function buildServer (ctx: ViteBuildContext) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
css: {
|
css: {
|
||||||
devSourcemap: ctx.nuxt.options.sourcemap.server
|
devSourcemap: !!ctx.nuxt.options.sourcemap.server
|
||||||
},
|
},
|
||||||
define: {
|
define: {
|
||||||
'process.server': true,
|
'process.server': true,
|
||||||
@ -106,7 +106,7 @@ export async function buildServer (ctx: ViteBuildContext) {
|
|||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
pureAnnotationsPlugin.vite({
|
pureAnnotationsPlugin.vite({
|
||||||
sourcemap: ctx.nuxt.options.sourcemap.server,
|
sourcemap: !!ctx.nuxt.options.sourcemap.server,
|
||||||
functions: ['defineComponent', 'defineAsyncComponent', 'defineNuxtLink', 'createClientOnly', 'defineNuxtPlugin', 'defineNuxtRouteMiddleware', 'defineNuxtComponent', 'useRuntimeConfig', 'defineRouteRules']
|
functions: ['defineComponent', 'defineAsyncComponent', 'defineNuxtLink', 'createClientOnly', 'defineNuxtPlugin', 'defineNuxtRouteMiddleware', 'defineNuxtComponent', 'useRuntimeConfig', 'defineRouteRules']
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
|
@ -99,7 +99,7 @@ export const bundle: NuxtBuilder['bundle'] = async (nuxt) => {
|
|||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
composableKeysPlugin.vite({
|
composableKeysPlugin.vite({
|
||||||
sourcemap: nuxt.options.sourcemap.server || nuxt.options.sourcemap.client,
|
sourcemap: !!nuxt.options.sourcemap.server || !!nuxt.options.sourcemap.client,
|
||||||
rootDir: nuxt.options.rootDir,
|
rootDir: nuxt.options.rootDir,
|
||||||
composables: nuxt.options.optimization.keyedComposables
|
composables: nuxt.options.optimization.keyedComposables
|
||||||
}),
|
}),
|
||||||
|
@ -30,12 +30,14 @@ function clientDevtool (ctx: WebpackConfigContext) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const prefix = ctx.nuxt.options.sourcemap.client === 'hidden' ? 'hidden-' : ''
|
||||||
|
|
||||||
if (!ctx.isDev) {
|
if (!ctx.isDev) {
|
||||||
ctx.config.devtool = 'source-map'
|
ctx.config.devtool = prefix + 'source-map'
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.config.devtool = 'eval-cheap-module-source-map'
|
ctx.config.devtool = prefix + 'eval-cheap-module-source-map'
|
||||||
}
|
}
|
||||||
|
|
||||||
function clientPerformance (ctx: WebpackConfigContext) {
|
function clientPerformance (ctx: WebpackConfigContext) {
|
||||||
|
@ -27,7 +27,12 @@ export function server (ctx: WebpackConfigContext) {
|
|||||||
function serverPreset (ctx: WebpackConfigContext) {
|
function serverPreset (ctx: WebpackConfigContext) {
|
||||||
ctx.config.output!.filename = 'server.mjs'
|
ctx.config.output!.filename = 'server.mjs'
|
||||||
|
|
||||||
ctx.config.devtool = ctx.nuxt.options.sourcemap.server ? ctx.isDev ? 'cheap-module-source-map' : 'source-map' : false
|
if (ctx.nuxt.options.sourcemap.server) {
|
||||||
|
const prefix = ctx.nuxt.options.sourcemap.server === 'hidden' ? 'hidden-' : ''
|
||||||
|
ctx.config.devtool = prefix + ctx.isDev ? 'cheap-module-source-map' : 'source-map'
|
||||||
|
} else {
|
||||||
|
ctx.config.devtool = false
|
||||||
|
}
|
||||||
|
|
||||||
ctx.config.optimization = {
|
ctx.config.optimization = {
|
||||||
splitChunks: false,
|
splitChunks: false,
|
||||||
|
@ -39,14 +39,14 @@ export const bundle: NuxtBuilder['bundle'] = async (nuxt) => {
|
|||||||
|
|
||||||
for (const config of webpackConfigs) {
|
for (const config of webpackConfigs) {
|
||||||
config.plugins!.push(DynamicBasePlugin.webpack({
|
config.plugins!.push(DynamicBasePlugin.webpack({
|
||||||
sourcemap: nuxt.options.sourcemap[config.name as 'client' | 'server']
|
sourcemap: !!nuxt.options.sourcemap[config.name as 'client' | 'server']
|
||||||
}))
|
}))
|
||||||
// Emit chunk errors if the user has opted in to `experimental.emitRouteChunkError`
|
// Emit chunk errors if the user has opted in to `experimental.emitRouteChunkError`
|
||||||
if (config.name === 'client' && nuxt.options.experimental.emitRouteChunkError) {
|
if (config.name === 'client' && nuxt.options.experimental.emitRouteChunkError) {
|
||||||
config.plugins!.push(new ChunkErrorPlugin())
|
config.plugins!.push(new ChunkErrorPlugin())
|
||||||
}
|
}
|
||||||
config.plugins!.push(composableKeysPlugin.webpack({
|
config.plugins!.push(composableKeysPlugin.webpack({
|
||||||
sourcemap: nuxt.options.sourcemap[config.name as 'client' | 'server'],
|
sourcemap: !!nuxt.options.sourcemap[config.name as 'client' | 'server'],
|
||||||
rootDir: nuxt.options.rootDir,
|
rootDir: nuxt.options.rootDir,
|
||||||
composables: nuxt.options.optimization.keyedComposables
|
composables: nuxt.options.optimization.keyedComposables
|
||||||
}))
|
}))
|
||||||
|
Loading…
Reference in New Issue
Block a user