Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(@angular-devkit/build-angular): allow configuring loaders for custom file extensions in application builder #26371

Merged
merged 1 commit into from
Nov 16, 2023

Commits on Nov 16, 2023

  1. feat(@angular-devkit/build-angular): allow configuring loaders for cu…

    …stom file extensions in application builder
    
    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.
    clydin committed Nov 16, 2023
    Configuration menu
    Copy the full SHA
    7f33e38 View commit details
    Browse the repository at this point in the history