File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -54,7 +54,8 @@ module.exports = (function () {
5454 */
5555export const bundle = async (
5656 filename : string ,
57- options : RNRBConfig = { }
57+ options : RNRBConfig = { } ,
58+ esbuildOptions : Omit < esbuild . BuildOptions , "write" | "entryPoints" | "alias" > = { } ,
5859) : Promise < string > => {
5960 const alias : Record < string , string > = { } ;
6061
@@ -71,6 +72,8 @@ export const bundle = async (
7172 alias [ "react-native" ] = "react-native-web" ;
7273 }
7374
75+ const { plugins, ...restOptions } = esbuildOptions ;
76+
7477 const bundled = await esbuild . build ( {
7578 entryPoints : [ filename ] ,
7679 bundle : true ,
@@ -139,7 +142,9 @@ export const bundle = async (
139142 } ) ;
140143 } ,
141144 } ,
145+ ...( plugins || [ ] )
142146 ] ,
147+ ...restOptions ,
143148 } ) ;
144149
145150 const code = bundled . outputFiles [ 0 ] ! . text ;
Original file line number Diff line number Diff line change 44 * @module
55 */
66
7+ import { BuildOptions } from "esbuild" ;
78import { isEntryFile } from "./babel" ;
89import { RNRBConfig , bundle , escape } from "./bundler" ;
910import { join } from "path" ;
@@ -47,3 +48,23 @@ export const transform = async (args: any /* TODO */) => {
4748
4849 return metroTransformer . transform ( args ) ;
4950} ;
51+
52+ export const createTransformer = ( esbuildOptions : Omit < BuildOptions , "write" | "entryPoints" | "alias" > = { } ) => {
53+ const transform = async ( args : any /* TODO */ ) => {
54+ const { filename, src } = args ;
55+ const isEntry = isEntryFile ( src , filename ) ;
56+ if ( isEntry ) {
57+ const res = await bundle ( filename , metroOptions , esbuildOptions ) ;
58+ return metroTransformer . transform ( {
59+ ...args ,
60+ src :
61+ "export default String.raw`" +
62+ escape ( res ) . replace ( / \$ \{ ( .* ?) \} / g, '\\$\\{$1\\}' ) +
63+ "`.replace(/\\\\([`${}])/g, '\\$1')" ,
64+ } ) ;
65+ }
66+
67+ return metroTransformer . transform ( args ) ;
68+ } ;
69+ return transform ;
70+ }
You can’t perform that action at this time.
0 commit comments