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 ,
@@ -17,6 +17,7 @@ import {
1717 createAngularSetupMiddlewaresPlugin ,
1818 createAngularSsrTransformPlugin ,
1919 createRemoveIdPrefixPlugin ,
20+ removeSourceMapsPlugin ,
2021} from '../../../tools/vite/plugins' ;
2122import { EsbuildLoaderOption , getDepOptimizationConfig } from '../../../tools/vite/utils' ;
2223import { loadProxyConfiguration } from '../../../utils' ;
@@ -151,6 +152,7 @@ export async function setupServer(
151152 define : ApplicationBuilderInternalOptions [ 'define' ] ,
152153 extensionMiddleware ?: Connect . NextHandleFunction [ ] ,
153154 indexHtmlTransformer ?: ( content : string ) => Promise < string > ,
155+ sourceMaps = true ,
154156 thirdPartySourcemaps = false ,
155157) : Promise < InlineConfig > {
156158 // dynamically import Vite for ESM compatibility
@@ -172,6 +174,34 @@ export async function setupServer(
172174 externalMetadata . explicitBrowser . length === 0 && ssrMode === ServerSsrMode . NoSsr ;
173175 const cacheDir = join ( serverOptions . cacheOptions . path , serverOptions . buildTarget . project , 'vite' ) ;
174176
177+ const plugins : Plugin [ ] = [
178+ createAngularLocaleDataPlugin ( ) ,
179+ createAngularSetupMiddlewaresPlugin ( {
180+ outputFiles,
181+ assets,
182+ indexHtmlTransformer,
183+ extensionMiddleware,
184+ componentStyles,
185+ templateUpdates,
186+ ssrMode,
187+ resetComponentUpdates : ( ) => templateUpdates . clear ( ) ,
188+ projectRoot : serverOptions . projectRoot ,
189+ } ) ,
190+ createRemoveIdPrefixPlugin ( externalMetadata . explicitBrowser ) ,
191+ await createAngularSsrTransformPlugin ( serverOptions . workspaceRoot ) ,
192+ await createAngularMemoryPlugin ( {
193+ virtualProjectRoot,
194+ outputFiles,
195+ templateUpdates,
196+ external : externalMetadata . explicitBrowser ,
197+ disableViteTransport : ! serverOptions . liveReload ,
198+ } ) ,
199+ ] ;
200+
201+ if ( ! sourceMaps ) {
202+ plugins . push ( removeSourceMapsPlugin ) ;
203+ }
204+
175205 const configuration : InlineConfig = {
176206 configFile : false ,
177207 envFile : false ,
@@ -183,7 +213,7 @@ export async function setupServer(
183213 // We use custom as we do not rely on Vite's htmlFallbackMiddleware and indexHtmlMiddleware.
184214 appType : 'custom' ,
185215 css : {
186- devSourcemap : true ,
216+ devSourcemap : sourceMaps ,
187217 } ,
188218 // Ensure custom 'file' loader build option entries are handled by Vite in application code that
189219 // reference third-party libraries. Relative usage is handled directly by the build and not Vite.
@@ -220,29 +250,7 @@ export async function setupServer(
220250 thirdPartySourcemaps ,
221251 define ,
222252 ) ,
223- plugins : [
224- createAngularLocaleDataPlugin ( ) ,
225- createAngularSetupMiddlewaresPlugin ( {
226- outputFiles,
227- assets,
228- indexHtmlTransformer,
229- extensionMiddleware,
230- componentStyles,
231- templateUpdates,
232- ssrMode,
233- resetComponentUpdates : ( ) => templateUpdates . clear ( ) ,
234- projectRoot : serverOptions . projectRoot ,
235- } ) ,
236- createRemoveIdPrefixPlugin ( externalMetadata . explicitBrowser ) ,
237- await createAngularSsrTransformPlugin ( serverOptions . workspaceRoot ) ,
238- await createAngularMemoryPlugin ( {
239- virtualProjectRoot,
240- outputFiles,
241- templateUpdates,
242- external : externalMetadata . explicitBrowser ,
243- disableViteTransport : ! serverOptions . liveReload ,
244- } ) ,
245- ] ,
253+ plugins,
246254 // Browser only optimizeDeps. (This does not run for SSR dependencies).
247255 optimizeDeps : getDepOptimizationConfig ( {
248256 // Only enable with caching since it causes prebundle dependencies to be cached
0 commit comments