From 9f4ac4d1242c30269d6671c42f381891f71c4728 Mon Sep 17 00:00:00 2001 From: Ignace Maes Date: Wed, 21 Aug 2024 20:21:55 +0200 Subject: [PATCH] use import.meta.glob for assets in app dir --- {public => app/assets}/images/ember.svg | 0 {public => app/assets}/images/embroider.svg | 0 {public => app/assets}/images/glimmer-ts.svg | 0 {public => app/assets}/images/glint.png | Bin {public => app/assets}/images/tailwind.svg | 0 {public => app/assets}/images/typescript.svg | 0 {public => app/assets}/images/vite.svg | 0 {public => app/assets}/images/volar.svg | 0 {public => app/assets}/images/warp-drive.svg | 0 app/helpers/import-asset.ts | 10 ++++ app/templates/about.gts | 20 ++++--- package.json | 6 +- pnpm-lock.yaml | 59 ++++--------------- tsconfig.json | 3 +- 14 files changed, 37 insertions(+), 61 deletions(-) rename {public => app/assets}/images/ember.svg (100%) rename {public => app/assets}/images/embroider.svg (100%) rename {public => app/assets}/images/glimmer-ts.svg (100%) rename {public => app/assets}/images/glint.png (100%) rename {public => app/assets}/images/tailwind.svg (100%) rename {public => app/assets}/images/typescript.svg (100%) rename {public => app/assets}/images/vite.svg (100%) rename {public => app/assets}/images/volar.svg (100%) rename {public => app/assets}/images/warp-drive.svg (100%) create mode 100644 app/helpers/import-asset.ts diff --git a/public/images/ember.svg b/app/assets/images/ember.svg similarity index 100% rename from public/images/ember.svg rename to app/assets/images/ember.svg diff --git a/public/images/embroider.svg b/app/assets/images/embroider.svg similarity index 100% rename from public/images/embroider.svg rename to app/assets/images/embroider.svg diff --git a/public/images/glimmer-ts.svg b/app/assets/images/glimmer-ts.svg similarity index 100% rename from public/images/glimmer-ts.svg rename to app/assets/images/glimmer-ts.svg diff --git a/public/images/glint.png b/app/assets/images/glint.png similarity index 100% rename from public/images/glint.png rename to app/assets/images/glint.png diff --git a/public/images/tailwind.svg b/app/assets/images/tailwind.svg similarity index 100% rename from public/images/tailwind.svg rename to app/assets/images/tailwind.svg diff --git a/public/images/typescript.svg b/app/assets/images/typescript.svg similarity index 100% rename from public/images/typescript.svg rename to app/assets/images/typescript.svg diff --git a/public/images/vite.svg b/app/assets/images/vite.svg similarity index 100% rename from public/images/vite.svg rename to app/assets/images/vite.svg diff --git a/public/images/volar.svg b/app/assets/images/volar.svg similarity index 100% rename from public/images/volar.svg rename to app/assets/images/volar.svg diff --git a/public/images/warp-drive.svg b/app/assets/images/warp-drive.svg similarity index 100% rename from public/images/warp-drive.svg rename to app/assets/images/warp-drive.svg diff --git a/app/helpers/import-asset.ts b/app/helpers/import-asset.ts new file mode 100644 index 0000000..3c284c2 --- /dev/null +++ b/app/helpers/import-asset.ts @@ -0,0 +1,10 @@ +const images = import.meta.glob('../assets/images/*.(svg|png)', { + eager: true, +}); + +export default function importAsset(assetName: string): string { + const imagePath = images[`../assets/images/${assetName}`] as + | { default: string } + | undefined; + return imagePath?.default ?? ''; +} diff --git a/app/templates/about.gts b/app/templates/about.gts index 3a8d911..f89b71a 100644 --- a/app/templates/about.gts +++ b/app/templates/about.gts @@ -3,6 +3,8 @@ import { RouteTemplate } from 'ember-polaris-pokedex/utils/ember-route-template' import Component from '@glimmer/component'; import HomeButton from 'ember-polaris-pokedex/components/home-button'; +import importAsset from 'ember-polaris-pokedex/helpers/import-asset'; + @RouteTemplate export default class ApplicationTemplate extends Component {