88
99import { readFile } from 'node:fs/promises' ;
1010import { join } from 'node:path' ;
11- import type { Connect , InlineConfig , SSROptions , ServerOptions } from 'vite' ;
11+ import type { Connect , InlineConfig , Plugin , SSROptions , ServerOptions } from 'vite' ;
1212import type { ComponentStyleRecord } from '../../../tools/vite/middlewares' ;
1313import {
1414 ServerSsrMode ,
1515 createAngularMemoryPlugin ,
1616 createAngularSetupMiddlewaresPlugin ,
1717 createAngularSsrTransformPlugin ,
1818 createRemoveIdPrefixPlugin ,
19+ removeSourceMapsPlugin ,
1920} from '../../../tools/vite/plugins' ;
2021import { EsbuildLoaderOption , getDepOptimizationConfig } from '../../../tools/vite/utils' ;
2122import { loadProxyConfiguration } from '../../../utils' ;
@@ -150,6 +151,7 @@ export async function setupServer(
150151 define : ApplicationBuilderInternalOptions [ 'define' ] ,
151152 extensionMiddleware ?: Connect . NextHandleFunction [ ] ,
152153 indexHtmlTransformer ?: ( content : string ) => Promise < string > ,
154+ sourceMaps = true ,
153155 thirdPartySourcemaps = false ,
154156) : Promise < InlineConfig > {
155157 // dynamically import Vite for ESM compatibility
@@ -171,6 +173,33 @@ export async function setupServer(
171173 externalMetadata . explicitBrowser . length === 0 && ssrMode === ServerSsrMode . NoSsr ;
172174 const cacheDir = join ( serverOptions . cacheOptions . path , serverOptions . buildTarget . project , 'vite' ) ;
173175
176+ const plugins : Plugin [ ] = [
177+ createAngularSetupMiddlewaresPlugin ( {
178+ outputFiles,
179+ assets,
180+ indexHtmlTransformer,
181+ extensionMiddleware,
182+ componentStyles,
183+ templateUpdates,
184+ ssrMode,
185+ resetComponentUpdates : ( ) => templateUpdates . clear ( ) ,
186+ projectRoot : serverOptions . projectRoot ,
187+ } ) ,
188+ createRemoveIdPrefixPlugin ( externalMetadata . explicitBrowser ) ,
189+ await createAngularSsrTransformPlugin ( serverOptions . workspaceRoot ) ,
190+ await createAngularMemoryPlugin ( {
191+ virtualProjectRoot,
192+ outputFiles,
193+ templateUpdates,
194+ external : externalMetadata . explicitBrowser ,
195+ disableViteTransport : ! serverOptions . liveReload ,
196+ } ) ,
197+ ] ;
198+
199+ if ( ! sourceMaps ) {
200+ plugins . push ( removeSourceMapsPlugin ) ;
201+ }
202+
174203 const configuration : InlineConfig = {
175204 configFile : false ,
176205 envFile : false ,
@@ -182,7 +211,7 @@ export async function setupServer(
182211 // We use custom as we do not rely on Vite's htmlFallbackMiddleware and indexHtmlMiddleware.
183212 appType : 'custom' ,
184213 css : {
185- devSourcemap : true ,
214+ devSourcemap : sourceMaps ,
186215 } ,
187216 // Ensure custom 'file' loader build option entries are handled by Vite in application code that
188217 // reference third-party libraries. Relative usage is handled directly by the build and not Vite.
@@ -219,28 +248,7 @@ export async function setupServer(
219248 thirdPartySourcemaps ,
220249 define ,
221250 ) ,
222- plugins : [
223- createAngularSetupMiddlewaresPlugin ( {
224- outputFiles,
225- assets,
226- indexHtmlTransformer,
227- extensionMiddleware,
228- componentStyles,
229- templateUpdates,
230- ssrMode,
231- resetComponentUpdates : ( ) => templateUpdates . clear ( ) ,
232- projectRoot : serverOptions . projectRoot ,
233- } ) ,
234- createRemoveIdPrefixPlugin ( externalMetadata . explicitBrowser ) ,
235- await createAngularSsrTransformPlugin ( serverOptions . workspaceRoot ) ,
236- await createAngularMemoryPlugin ( {
237- virtualProjectRoot,
238- outputFiles,
239- templateUpdates,
240- external : externalMetadata . explicitBrowser ,
241- disableViteTransport : ! serverOptions . liveReload ,
242- } ) ,
243- ] ,
251+ plugins,
244252 // Browser only optimizeDeps. (This does not run for SSR dependencies).
245253 optimizeDeps : getDepOptimizationConfig ( {
246254 // Only enable with caching since it causes prebundle dependencies to be cached
0 commit comments