feat(@angular/build): support import attribute based loader configuration #28040
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When using the
application
builder, aloader
import attribute is now available for use with import statements and expressions. The presence of the import attribute takes precedence over all other loading behavior including JS/TS and anyloader
build option values. This allows per file control over loading behavior. For general loading for all files of an otherwise unsupported file type, theloader
build option is recommended.For the import attribute, the following loader values are supported:
text
- inlines the content as a stringbinary
- inlines the content as a Uint8Arrayfile
- emits the file and provides the runtime location of the fileUnfortunately, at this time, TypeScript does not support type definitions that are based on import attribute values. The use of
@ts-expect-error
or the use of individual type definition files (assuming the file is only imported with the same loader attribute) is currently required.Additionally, the TypeScript
module
option must be set toesnext
to allow TypeScript to successfully build the application code.As an example, an SVG file can be imported as text via:
When using the development server and a file that is referenced from a Node.js package with a loader attribute, the package must be excluded from prebundling via the development server
prebundle
option. This does not apply to relative file references.This feature provides the bundling aspects of #26575. TypeScript type definition support would provide the full feature set for that issue but is currently blocked on TypeScript upstream.