@@ -13,7 +13,7 @@ import assert from 'node:assert';
13
13
import { readFile } from 'node:fs/promises' ;
14
14
import { builtinModules , isBuiltin } from 'node:module' ;
15
15
import { join } from 'node:path' ;
16
- import type { Connect , DepOptimizationConfig , InlineConfig , ViteDevServer } from 'vite' ;
16
+ import type { Connect , InlineConfig , ViteDevServer } from 'vite' ;
17
17
import type { ComponentStyleRecord } from '../../tools/vite/middlewares' ;
18
18
import {
19
19
ServerSsrMode ,
@@ -23,6 +23,7 @@ import {
23
23
createAngularSsrTransformPlugin ,
24
24
createRemoveIdPrefixPlugin ,
25
25
} from '../../tools/vite/plugins' ;
26
+ import { EsbuildLoaderOption , getDepOptimizationConfig } from '../../tools/vite/utils' ;
26
27
import { loadProxyConfiguration , normalizeSourceMaps } from '../../utils' ;
27
28
import { useComponentStyleHmr , useComponentTemplateHmr } from '../../utils/environment-options' ;
28
29
import { loadEsmModule } from '../../utils/load-esm' ;
@@ -32,7 +33,6 @@ import {
32
33
BuildOutputFileType ,
33
34
type ExternalResultMetadata ,
34
35
JavaScriptTransformer ,
35
- getFeatureSupport ,
36
36
getSupportedBrowsers ,
37
37
isZonelessApp ,
38
38
transformSupportedBrowsersToTargets ,
@@ -775,91 +775,6 @@ export async function setupServer(
775
775
return configuration ;
776
776
}
777
777
778
- type ViteEsBuildPlugin = NonNullable <
779
- NonNullable < DepOptimizationConfig [ 'esbuildOptions' ] > [ 'plugins' ]
780
- > [ 0 ] ;
781
-
782
- type EsbuildLoaderOption = Exclude < DepOptimizationConfig [ 'esbuildOptions' ] , undefined > [ 'loader' ] ;
783
-
784
- function getDepOptimizationConfig ( {
785
- disabled,
786
- exclude,
787
- include,
788
- target,
789
- zoneless,
790
- prebundleTransformer,
791
- ssr,
792
- loader,
793
- thirdPartySourcemaps,
794
- } : {
795
- disabled : boolean ;
796
- exclude : string [ ] ;
797
- include : string [ ] ;
798
- target : string [ ] ;
799
- prebundleTransformer : JavaScriptTransformer ;
800
- ssr : boolean ;
801
- zoneless : boolean ;
802
- loader ?: EsbuildLoaderOption ;
803
- thirdPartySourcemaps : boolean ;
804
- } ) : DepOptimizationConfig {
805
- const plugins : ViteEsBuildPlugin [ ] = [
806
- {
807
- name : 'angular-browser-node-built-in' ,
808
- setup ( build ) {
809
- // This namespace is configured by vite.
810
- // @see : https://github.com/vitejs/vite/blob/a1dd396da856401a12c921d0cd2c4e97cb63f1b5/packages/vite/src/node/optimizer/esbuildDepPlugin.ts#L109
811
- build . onLoad ( { filter : / .* / , namespace : 'browser-external' } , ( args ) => {
812
- if ( ! isBuiltin ( args . path ) ) {
813
- return ;
814
- }
815
-
816
- return {
817
- errors : [
818
- {
819
- text : `The package "${ args . path } " wasn't found on the file system but is built into node.` ,
820
- } ,
821
- ] ,
822
- } ;
823
- } ) ;
824
- } ,
825
- } ,
826
- {
827
- name : `angular-vite-optimize-deps${ ssr ? '-ssr' : '' } ${
828
- thirdPartySourcemaps ? '-vendor-sourcemap' : ''
829
- } `,
830
- setup ( build ) {
831
- build . onLoad ( { filter : / \. [ c m ] ? j s $ / } , async ( args ) => {
832
- return {
833
- contents : await prebundleTransformer . transformFile ( args . path ) ,
834
- loader : 'js' ,
835
- } ;
836
- } ) ;
837
- } ,
838
- } ,
839
- ] ;
840
-
841
- return {
842
- // Exclude any explicitly defined dependencies (currently build defined externals)
843
- exclude,
844
- // NB: to disable the deps optimizer, set optimizeDeps.noDiscovery to true and optimizeDeps.include as undefined.
845
- // Include all implict dependencies from the external packages internal option
846
- include : disabled ? undefined : include ,
847
- noDiscovery : disabled ,
848
- // Add an esbuild plugin to run the Angular linker on dependencies
849
- esbuildOptions : {
850
- // Set esbuild supported targets.
851
- target,
852
- supported : getFeatureSupport ( target , zoneless ) ,
853
- plugins,
854
- loader,
855
- define : {
856
- 'ngServerMode' : `${ ssr } ` ,
857
- } ,
858
- resolveExtensions : [ '.mjs' , '.js' , '.cjs' ] ,
859
- } ,
860
- } ;
861
- }
862
-
863
778
/**
864
779
* Checks if the given value is an absolute URL.
865
780
*
0 commit comments