mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-22 06:41:45 +08:00
When using the `application` builder, a new `loader` option is now available for use. The option allows a project to define the type of loader to use with a specified file extension. A file with the defined extension can then used within the application code via an import statement or dynamic import expression, for instance. The available loaders that can be used are: * `text` - inlines the content as a string * `binary` - inlines the content as a Uint8Array * `file` - emits the file and provides the runtime location of the file * `empty` - considers the content to be empty and will not include it in bundles The loader option is an object-based option with the keys used to define the file extension and the values used to define the loader type. An example to inline the content of SVG files into the bundled application would be as follows: ``` loader: { ".svg": "text" } ``` An SVG file can then be imported: ``` import contents from './some-file.svg'; ``` Additionally, TypeScript needs to be aware of the module type for the import to prevent type-checking errors during the build. This can be accomplished with an additional type definition file within the application source code (`src/types.d.ts`, for example) with the following or similar content: ``` declare module "*.svg" { const content: string; export default content; } ``` The default project configuration is already setup to use any type definition files present in the project source directories. If the TypeScript configuration for the project has been altered, the tsconfig may need to be adjusted to reference this newly added type definition file.