我有一个Weapon
类,它至少有一个图标.
export default abstract class Weapon {
icons: string[]; // May be the wrong type to use here
constructor(iconOrIcons: string | string[]) {
this.icons = typeof iconOrIcons === 'string' ? [iconOrIcons] : iconOrIcons;
}
}
每个图标是.webp
,我是这样导入它们的:
import icon from '../../../assets/weapons/swords/dagger.webp';
import Sword from './Sword';
export default new Sword(icon);
然而,这些文件只是在我的项目中(甚至没有try 渲染图像),webpack抛出:
Error: Module parse failed: Unexpected character '♦' (1:5)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)
好的,webpack说得很清楚,我需要一台装载机.但我不清楚如何将装载机添加到angular.json
.
也可能是这样,我实际上并不需要/不想导入.webp
文件本身,我可以只使用指向这些资源的URL.在这种情况下,理想情况下,我希望有一些更好的方法来声明这些URL,而不仅仅是在我的Weapon
个实例上使用任意的字符串文字.