Skip to content

Commit

Permalink
use import.meta.glob for assets in app dir
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnaceMaes committed Aug 21, 2024
1 parent 808de32 commit 9f4ac4d
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 61 deletions.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
10 changes: 10 additions & 0 deletions app/helpers/import-asset.ts
Original file line number Diff line number Diff line change
@@ -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 ?? '';
}
20 changes: 11 additions & 9 deletions app/templates/about.gts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
<template>
Expand Down Expand Up @@ -113,47 +115,47 @@ export default class ApplicationTemplate extends Component {

<div class='mt-16 grid grid-cols-3 gap-8 md:grid-cols-6 lg:grid-cols-9'>
<img
src='/images/ember.svg'
src={{importAsset 'ember.svg'}}
alt='ember'
class='h-full w-full drop-shadow-md'
/>
<img
src='/images/embroider.svg'
src={{importAsset 'embroider.svg'}}
alt='embroider'
class='h-full w-full drop-shadow-md'
/>
<img
src='/images/vite.svg'
src={{importAsset 'vite.svg'}}
alt='vite'
class='h-full w-full drop-shadow-md'
/>
<img
src='/images/volar.svg'
src={{importAsset 'volar.svg'}}
alt='volar'
class='h-full w-full drop-shadow-md'
/>
<img
src='/images/glint.png'
src={{importAsset 'glint.png'}}
alt='glint'
class='h-full w-full drop-shadow-md'
/>
<img
src='/images/typescript.svg'
src={{importAsset 'typescript.svg'}}
alt='typescript'
class='h-full w-full drop-shadow-md'
/>
<img
src='/images/warp-drive.svg'
src={{importAsset 'warp-drive.svg'}}
alt='Warp Drive'
class='h-full w-full drop-shadow-md'
/>
<img
src='/images/glimmer-ts.svg'
src={{importAsset 'glimmer-ts.svg'}}
alt='Glimmer TS'
class='h-full w-full drop-shadow-md'
/>
<img
src='/images/tailwind.svg'
src={{importAsset 'tailwind.svg'}}
alt='TailwindCSS'
class='h-full w-full drop-shadow-md'
/>
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
},
"devDependencies": {
"@babel/core": "^7.25.2",
"@babel/eslint-parser": "^7.24.7",
"@babel/plugin-proposal-decorators": "^7.24.7",
"@ember-data-types/adapter": "5.4.0-alpha.98",
"@ember-data-types/graph": "5.4.0-alpha.98",
"@ember-data-types/json-api": "5.4.0-alpha.98",
Expand All @@ -38,8 +40,6 @@
"@ember-data-types/serializer": "5.4.0-alpha.98",
"@ember-data-types/store": "5.4.0-alpha.98",
"@ember-data-types/tracking": "5.4.0-alpha.98",
"@babel/eslint-parser": "^7.24.7",
"@babel/plugin-proposal-decorators": "^7.24.7",
"@ember/optional-features": "^2.1.0",
"@ember/string": "^3.1.1",
"@ember/test-helpers": "^3.3.0",
Expand All @@ -54,6 +54,7 @@
"@glint/environment-ember-loose": "1.4.1-unstable.01b8deb",
"@glint/environment-ember-template-imports": "1.4.1-unstable.01b8deb",
"@glint/template": "1.4.1-unstable.01b8deb",
"@rollup/plugin-babel": "^6.0.4",
"@tsconfig/ember": "^3.0.8",
"@types/dom-view-transitions": "^1.0.5",
"@types/qunit": "^2.19.10",
Expand All @@ -62,7 +63,6 @@
"@typescript-eslint/parser": "^8.1.0",
"@warp-drive-types/core-types": "0.0.0-alpha.84",
"autoprefixer": "^10.0.2",
"@rollup/plugin-babel": "^6.0.4",
"concurrently": "^8.2.2",
"ember-auto-import": "^2.7.4",
"ember-cli": "~5.10.0",
Expand Down
59 changes: 11 additions & 48 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"./node_modules/@warp-drive/ember/unstable-preview-types",
"./node_modules/ember-data-types/unstable-preview-types",
"./node_modules/@types/dom-view-transitions",
"ember-source/types"
"ember-source/types",
"vite/client"
]
},
"glint": {
Expand Down

0 comments on commit 9f4ac4d

Please sign in to comment.