Skip to content

Instantly share code, notes, and snippets.

@shrey18111
Last active July 11, 2019 23:15
Show Gist options
  • Save shrey18111/050c379f28e64e2397aabf6a15a77f17 to your computer and use it in GitHub Desktop.
Save shrey18111/050c379f28e64e2397aabf6a15a77f17 to your computer and use it in GitHub Desktop.
Metro setup for importing assets from parent directory
let path = require("path")
module.exports = {
getTransformModulePath() {
return require.resolve("react-native-typescript-transformer")
},
sourceExts: ["ts", "tsx"],
// Set projectRoot to the web front-end root (Realization 1 above)
projectRoot: path.resolve(__dirname, "../assets/javascripts"),
// Set watchFolders to include the current directory, parent node_modules
// and the mobile node_modules (Realization 2 above)
watchFolders: [
path.resolve(__dirname),
path.resolve(__dirname, "./node_modules"),
path.resolve(__dirname, "../node_modules"),
],
resolver: {
// Set extraNodeModules to include the directories that you want to import
// files from (in our case, we wanted to import files specifically from
// util and types)
extraNodeModules: {
util: path.resolve(__dirname, "../assets/javascripts/util"),
types: path.resolve(__dirname, "../assets/javascripts/types"),
},
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment