Skip to content

Commit 1e947a5

Browse files
committed
Bundle image as base64
1 parent 1a222cb commit 1e947a5

File tree

12 files changed

+130
-6
lines changed

12 files changed

+130
-6
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React from "react";
2+
import { webViewRender } from "react-native-react-bridge/lib/web";
3+
import bmp from "./twitter.bmp";
4+
import gif from "./twitter.gif";
5+
import png from "./twitter.png";
6+
import jpg from "./twitter.jpg";
7+
import jpeg from "./twitter.jpeg";
8+
import webp from "./twitter.webp";
9+
import svg from "./twitter.svg";
10+
11+
const App = () => {
12+
return (
13+
<div>
14+
<img src={bmp} />
15+
<img src={gif} />
16+
<img src={png} />
17+
<img src={jpg} />
18+
<img src={jpeg} />
19+
<img src={webp} />
20+
<img src={svg} />
21+
</div>
22+
);
23+
};
24+
25+
export default webViewRender(App);

fixtures/twitter.bmp

625 KB
Binary file not shown.

fixtures/twitter.gif

3.35 KB
Loading

fixtures/twitter.jpeg

11.8 KB
Loading

fixtures/twitter.jpg

11.8 KB
Loading

fixtures/twitter.png

9.26 KB
Loading

fixtures/twitter.svg

Lines changed: 20 additions & 0 deletions
Loading

fixtures/twitter.webp

7.51 KB
Loading

src/plugin/__snapshots__/metro.spec.js.snap

Lines changed: 25 additions & 0 deletions
Large diffs are not rendered by default.

src/plugin/metro.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import Metro from "metro";
22

33
const babelTransformerPath = require.resolve("./transformer");
4+
const sourceExts = ["js", "ts", "jsx", "tsx"];
5+
const imageExts = ["bmp", "gif", "png", "jpg", "jpeg", "webp", "svg"];
46

57
export const bundle = async (filename) => {
68
const config = await Metro.loadConfig();
7-
config.resolver.sourceExts = ["js", "ts", "jsx", "tsx", "css"];
9+
config.resolver.sourceExts = [...sourceExts, ...imageExts, "css"];
10+
config.resolver.assetExts = config.resolver.assetExts.filter(
11+
(ext) => !imageExts.includes(ext)
12+
);
813
config.transformer.babelTransformerPath = babelTransformerPath;
14+
915
const { code, map } = await Metro.runBuild(config, {
1016
entry: filename,
1117
platform: "web",

0 commit comments

Comments
 (0)