@@ -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 ,
@@ -791,91 +791,6 @@ export async function setupServer(
791
791
return configuration ;
792
792
}
793
793
794
- type ViteEsBuildPlugin = NonNullable <
795
- NonNullable < DepOptimizationConfig [ 'esbuildOptions' ] > [ 'plugins' ]
796
- > [ 0 ] ;
797
-
798
- type EsbuildLoaderOption = Exclude < DepOptimizationConfig [ 'esbuildOptions' ] , undefined > [ 'loader' ] ;
799
-
800
- function getDepOptimizationConfig ( {
801
- disabled,
802
- exclude,
803
- include,
804
- target,
805
- zoneless,
806
- prebundleTransformer,
807
- ssr,
808
- loader,
809
- thirdPartySourcemaps,
810
- } : {
811
- disabled : boolean ;
812
- exclude : string [ ] ;
813
- include : string [ ] ;
814
- target : string [ ] ;
815
- prebundleTransformer : JavaScriptTransformer ;
816
- ssr : boolean ;
817
- zoneless : boolean ;
818
- loader ?: EsbuildLoaderOption ;
819
- thirdPartySourcemaps : boolean ;
820
- } ) : DepOptimizationConfig {
821
- const plugins : ViteEsBuildPlugin [ ] = [
822
- {
823
- name : 'angular-browser-node-built-in' ,
824
- setup ( build ) {
825
- // This namespace is configured by vite.
826
- // @see : https://github.com/vitejs/vite/blob/a1dd396da856401a12c921d0cd2c4e97cb63f1b5/packages/vite/src/node/optimizer/esbuildDepPlugin.ts#L109
827
- build . onLoad ( { filter : / .* / , namespace : 'browser-external' } , ( args ) => {
828
- if ( ! isBuiltin ( args . path ) ) {
829
- return ;
830
- }
831
-
832
- return {
833
- errors : [
834
- {
835
- text : `The package "${ args . path } " wasn't found on the file system but is built into node.` ,
836
- } ,
837
- ] ,
838
- } ;
839
- } ) ;
840
- } ,
841
- } ,
842
- {
843
- name : `angular-vite-optimize-deps${ ssr ? '-ssr' : '' } ${
844
- thirdPartySourcemaps ? '-vendor-sourcemap' : ''
845
- } `,
846
- setup ( build ) {
847
- build . onLoad ( { filter : / \. [ c m ] ? j s $ / } , async ( args ) => {
848
- return {
849
- contents : await prebundleTransformer . transformFile ( args . path ) ,
850
- loader : 'js' ,
851
- } ;
852
- } ) ;
853
- } ,
854
- } ,
855
- ] ;
856
-
857
- return {
858
- // Exclude any explicitly defined dependencies (currently build defined externals)
859
- exclude,
860
- // NB: to disable the deps optimizer, set optimizeDeps.noDiscovery to true and optimizeDeps.include as undefined.
861
- // Include all implict dependencies from the external packages internal option
862
- include : disabled ? undefined : include ,
863
- noDiscovery : disabled ,
864
- // Add an esbuild plugin to run the Angular linker on dependencies
865
- esbuildOptions : {
866
- // Set esbuild supported targets.
867
- target,
868
- supported : getFeatureSupport ( target , zoneless ) ,
869
- plugins,
870
- loader,
871
- define : {
872
- 'ngServerMode' : `${ ssr } ` ,
873
- } ,
874
- resolveExtensions : [ '.mjs' , '.js' , '.cjs' ] ,
875
- } ,
876
- } ;
877
- }
878
-
879
794
/**
880
795
* Checks if the given value is an absolute URL.
881
796
*
0 commit comments