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

Support Raw Loading with application and builder-esbuild #26368

Closed
mcdenhoed opened this issue Nov 15, 2023 · 9 comments
Closed

Support Raw Loading with application and builder-esbuild #26368

mcdenhoed opened this issue Nov 15, 2023 · 9 comments

Comments

@mcdenhoed
Copy link

Command

build, serve

Description

I have some raw text files that I need to include in my build. To load them with builder-based builds, I am using the webpack raw-loader plugin.

I currently import them as follows:

import contents from "raw-loader!./some-text-file.txt";

It would be amazing if I could do something similar from within the new esbuild-based loader. I saw that vite allows for a ?raw suffix on imports to do just this, but it did not seem to work when I tried it in Angular.

Hopefully I'm just missing something here, but I didn't see this called out in the documentation.

Describe the solution you'd like

No response

Describe alternatives you've considered

No response

@clydin
Copy link
Member

clydin commented Nov 15, 2023

You can actually use import contents from "./some-text-file.txt";

To avoid a TypeScript error, you'll also need to add a type definition file (e.g., src/types.d.ts) with the following:

declare module "*.txt" {
  const content: string;
  export default content;
}

We are also evaluating further customization options for other file types in a future release.

@clydin clydin closed this as completed Nov 15, 2023
@mcdenhoed
Copy link
Author

Good to know, thanks! One follow-up question. Should this work for extensions other than .txt? I'm trying to use it on other extensions and am getting a message about no loader being configured for that extension.

@clydin
Copy link
Member

clydin commented Nov 15, 2023

Currently just .txt extensions but we are evaluating the inclusion of an additional build option to support configuring other extensions.

@mcdenhoed
Copy link
Author

That would be a big 👍 from me. My specific use-case is that I'm bundling .frag and .vert WebGL shader sources, and it's nice to keep those with their real extension so that the IDE handles them properly.

@clydin
Copy link
Member

clydin commented Nov 16, 2023

That would be a big 👍 from me. My specific use-case is that I'm bundling .frag and .vert WebGL shader sources, and it's nice to keep those with their real extension so that the IDE handles them properly.

This is now in review here: #26371

@mcdenhoed
Copy link
Author

Awesome, thank you!!

@reduckted
Copy link

@clydin This doesn't seem to be included in 17.0.2. Any ideas on when we can expect to see this?

@alan-agius4
Copy link
Collaborator

This will be available in 17.1.0 which is is currently in prerelease.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Dec 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants