typescript - Rollup + Typescript + 将图片加载为 base64
问题描述
尝试使用 Rollup 预加载图像时遇到问题。所有应该起作用的废话都不起作用,不知道为什么。有没有人设法使它工作?这是我在 rollup.congig.js 中的内容:
import image from 'rollup-plugin-image'
...
plugins: [
image(),
json(),
resolve(),
commonjs(),
typescript({
typescript: require('typescript'),
}),
(process.env.BUILD === 'production' ? terser() : {})
这是我在来源中的内容:
import CAR_IMAGE from "../resources/expand.png";
最后我从 rtp2 pluging 得到一个错误,上面写着:
语义错误 TS 2307,找不到模块“../resources/expand.png”
奇怪的是,我与其他各种用于汇总的图像加载插件一样。路径正确,图像在那里。我已经对这个错误发疯了=((
更新:这是可重现此错误的存储库:
https://github.com/AntonPilyak/rollup-image-bug
更新 2:已创建错误:
https://github.com/rollup/rollup-plugin-url/issues/22
https://github.com/alwayssonlinetxm/rollup-plugin-img/issues/5
https://github.com/rollup/rollup-plugin-image/issues/10
怎么会这么烂?=(((
解决方案
在 rollup.config.js中用这个包替换rollup-plugin-image包。
并在插件中添加如下内容
plugins: [
image({
extensions: /\.(png|jpg|jpeg|gif|svg)$/,
limit: 10000
}),........
declaration.d.ts
然后在根项目中创建一个文件名。添加以下片段
declare module '*.png' {
const value: any;
export default value;
}
在您的tsconfig.json中添加此代码段
"include": ["src","src/declaration.d.ts"],
在 CLI 中重新运行汇总。它会工作的!
推荐阅读
- blackberry - 我的 BYOD 应用程序显示 Application Access Denied 设备已越狱
- mysql - 如果 ip 地址存在于另一个表 MYSQL 中,则增加一个表中的计数器列
- javascript - 在vue中使用路由器更改视图时销毁我的计数器实例
- identityserver4 - 将身份服务器 4 部署到 azure 应用服务
- python - 字符串列表到一个字符串以调用 API
- sql - 将开始日期时间结束日期时间拆分为每天的小时持续时间
- php - Search in PHP and XML
- python - 将 dict 的值与数据帧的两列的值匹配,并将第三列的值替换为 dict 的键
- php - 组合三个字符串(日、月、年)并计算下一个日期(PHP)
- vuetify.js - 缩小 v-card 时保持 v-img 的右侧可见