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

Ability to require(...) an image file within Typescript #7011

Closed
pcroc opened this issue Jul 17, 2017 · 3 comments
Closed

Ability to require(...) an image file within Typescript #7011

pcroc opened this issue Jul 17, 2017 · 3 comments

Comments

@pcroc
Copy link

pcroc commented Jul 17, 2017

Bug Report or Feature Request (mark with an x)

- [ ] bug report -> please search issues before submitting
- [x] feature request

Versions.

@angular/cli: 1.2.1 (e)
node: 7.9.0
os: linux x64
@angular/animations: 4.2.6
@angular/common: 4.2.6
@angular/compiler: 4.2.6
@angular/core: 4.2.6
@angular/forms: 4.2.6
@angular/http: 4.2.6
@angular/platform-browser: 4.2.6
@angular/platform-browser-dynamic: 4.2.6
@angular/router: 4.2.6
@angular/cli: 1.2.1
@angular/compiler-cli: 4.2.6

Desired functionality.

I'm processing templates with html-loader so that webpack will optimize and fingerprint image files that are referenced in the template. However, I would like to be able to reference an image file within Typescript code, and have the same effect.

This works (HTML), and the image is processed by webpack:
<img src="../image/img1.png">

This doesn't work (Typescript):
let carouselImage = require('../images/img1.png');

The following error is output:
ERROR in xxx.ts (299,22): Cannot find name 'require'.

Mention any other details that might be useful.

See issues #2231 and #3415 regarding processing of image files using webpack.

@filipesilva
Copy link
Contributor

I'm sorry but this isn't something we are looking at adding.

@yjaaidi
Copy link

yjaaidi commented May 3, 2018

Hi @pcroc,

You can simply add declare var require: (path: string) => any to src/typings.d.ts.

@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 Sep 8, 2019
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

3 participants