diff --git a/examples/LaftelVideo/babel.config.js b/examples/LaftelVideo/babel.config.js index f842b77f..807a69f2 100644 --- a/examples/LaftelVideo/babel.config.js +++ b/examples/LaftelVideo/babel.config.js @@ -1,3 +1,17 @@ +const path = require('path'); +const pak = require('../package.json'); + module.exports = { presets: ['module:metro-react-native-babel-preset'], + plugins: [ + [ + 'module-resolver', + { + extensions: ['.tsx', '.ts', '.js', '.json'], + alias: { + [pak.name]: path.join(__dirname, '../..', pak.source), + }, + }, + ], + ], }; diff --git a/examples/LaftelVideo/metro.config.js b/examples/LaftelVideo/metro.config.js index e91aba93..dc81a956 100644 --- a/examples/LaftelVideo/metro.config.js +++ b/examples/LaftelVideo/metro.config.js @@ -1,11 +1,34 @@ -/** - * Metro configuration for React Native - * https://github.com/facebook/react-native - * - * @format - */ +const path = require('path'); +const escape = require('escape-string-regexp'); +const exclusionList = require('metro-config/src/defaults/exclusionList'); +const pak = require('../package.json'); + +const root = path.resolve(__dirname, '../..'); + +const modules = Object.keys({ + ...pak.peerDependencies, +}); module.exports = { + projectRoot: __dirname, + watchFolders: [root], + + // We need to make sure that only one version is loaded for peerDependencies + // So we block them at the root, and alias them to the versions in example's node_modules + resolver: { + blacklistRE: exclusionList( + modules.map( + (m) => + new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`) + ) + ), + + extraNodeModules: modules.reduce((acc, name) => { + acc[name] = path.join(__dirname, 'node_modules', name); + return acc; + }, {}), + }, + transformer: { getTransformOptions: async () => ({ transform: { diff --git a/examples/LaftelVideo/package.json b/examples/LaftelVideo/package.json index 6bd64f9e..a65c9495 100644 --- a/examples/LaftelVideo/package.json +++ b/examples/LaftelVideo/package.json @@ -25,6 +25,7 @@ "@typescript-eslint/eslint-plugin": "^5.37.0", "@typescript-eslint/parser": "^5.37.0", "babel-jest": "^26.6.3", + "babel-plugin-module-resolver": "^5.0.0", "eslint": "^7.32.0", "jest": "^26.6.3", "metro-react-native-babel-preset": "0.72.3", diff --git a/examples/LaftelVideo/react-native.config.js b/examples/LaftelVideo/react-native.config.js new file mode 100644 index 00000000..949042b7 --- /dev/null +++ b/examples/LaftelVideo/react-native.config.js @@ -0,0 +1,10 @@ +const path = require('path'); +const pak = require('../package.json'); + +module.exports = { + dependencies: { + [pak.name]: { + root: path.join(__dirname, '../..'), + }, + }, +};