mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-22 06:41:45 +08:00
fix(@angular/build): automatically resolve .mjs
files when using Vite
Previously, ESM file resolution without extensions failed when using Vite, causing issues in module loading. This commit addresses the problem by automatically resolving `.mjs` files, aligning the behavior with the application builder and ensuring consistent module resolution across different build tools. **NB**: This is a workaround as valid ESM imports should always have an extension. Closes #27841
This commit is contained in:
parent
9b702e1148
commit
2324d5a2ec
@ -677,6 +677,7 @@ function getDepOptimizationConfig({
|
|||||||
supported: getFeatureSupport(target, zoneless),
|
supported: getFeatureSupport(target, zoneless),
|
||||||
plugins,
|
plugins,
|
||||||
loader,
|
loader,
|
||||||
|
resolveExtensions: ['.mjs', '.js', '.cjs'],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -360,7 +360,7 @@ function getEsBuildCommonOptions(options: NormalizedApplicationBuildOptions): Bu
|
|||||||
format: 'esm',
|
format: 'esm',
|
||||||
assetNames: outputNames.media,
|
assetNames: outputNames.media,
|
||||||
conditions: ['es2020', 'es2015', 'module'],
|
conditions: ['es2020', 'es2015', 'module'],
|
||||||
resolveExtensions: ['.ts', '.tsx', '.mjs', '.js'],
|
resolveExtensions: ['.ts', '.tsx', '.mjs', '.js', '.cjs'],
|
||||||
metafile: true,
|
metafile: true,
|
||||||
legalComments: options.extractLicenses ? 'none' : 'eof',
|
legalComments: options.extractLicenses ? 'none' : 'eof',
|
||||||
logLevel: options.verbose && !jsonLogs ? 'debug' : 'silent',
|
logLevel: options.verbose && !jsonLogs ? 'debug' : 'silent',
|
||||||
|
@ -63,7 +63,7 @@ export function createGlobalScriptsBundleOptions(
|
|||||||
assetNames: outputNames.media,
|
assetNames: outputNames.media,
|
||||||
mainFields: ['script', 'browser', 'main'],
|
mainFields: ['script', 'browser', 'main'],
|
||||||
conditions: ['script'],
|
conditions: ['script'],
|
||||||
resolveExtensions: ['.mjs', '.js'],
|
resolveExtensions: ['.mjs', '.js', '.cjs'],
|
||||||
logLevel: options.verbose && !jsonLogs ? 'debug' : 'silent',
|
logLevel: options.verbose && !jsonLogs ? 'debug' : 'silent',
|
||||||
metafile: true,
|
metafile: true,
|
||||||
minify: optimizationOptions.scripts,
|
minify: optimizationOptions.scripts,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user