2023-06-30 10:55:56 +02:00
|
|
|
// Metro configuration for React Native
|
2024-05-21 11:12:20 +02:00
|
|
|
// https://reactnative.dev/docs/metro
|
2020-11-05 18:58:23 +02:00
|
|
|
|
|
|
|
// The technique below to get the symlinked packages to work with the Metro
|
|
|
|
// bundler comes from this comment:
|
|
|
|
//
|
|
|
|
// https://github.com/facebook/metro/issues/1#issuecomment-501143843
|
|
|
|
//
|
|
|
|
// Perhaps also investigate this technique as it's specifically for Lerna:
|
|
|
|
//
|
|
|
|
// https://github.com/facebook/metro/issues/1#issuecomment-511228599
|
|
|
|
|
|
|
|
const path = require('path');
|
2024-05-21 11:12:20 +02:00
|
|
|
const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');
|
2020-11-05 18:58:23 +02:00
|
|
|
|
2023-01-20 19:33:19 +02:00
|
|
|
const localPackages = {
|
|
|
|
'@joplin/lib': path.resolve(__dirname, '../lib/'),
|
|
|
|
'@joplin/renderer': path.resolve(__dirname, '../renderer/'),
|
2024-03-11 17:02:15 +02:00
|
|
|
'@joplin/turndown': path.resolve(__dirname, '../turndown/'),
|
|
|
|
'@joplin/turndown-plugin-gfm': path.resolve(__dirname, '../turndown-plugin-gfm/'),
|
2023-09-21 10:12:40 +02:00
|
|
|
'@joplin/editor': path.resolve(__dirname, '../editor/'),
|
2023-01-20 19:33:19 +02:00
|
|
|
'@joplin/tools': path.resolve(__dirname, '../tools/'),
|
2023-07-28 12:31:59 +02:00
|
|
|
'@joplin/utils': path.resolve(__dirname, '../utils/'),
|
2023-01-20 19:33:19 +02:00
|
|
|
'@joplin/fork-htmlparser2': path.resolve(__dirname, '../fork-htmlparser2/'),
|
|
|
|
'@joplin/fork-uslug': path.resolve(__dirname, '../fork-uslug/'),
|
|
|
|
'@joplin/react-native-saf-x': path.resolve(__dirname, '../react-native-saf-x/'),
|
|
|
|
'@joplin/react-native-alarm-notification': path.resolve(__dirname, '../react-native-alarm-notification/'),
|
2023-07-18 15:58:06 +02:00
|
|
|
'@joplin/fork-sax': path.resolve(__dirname, '../fork-sax/'),
|
|
|
|
};
|
|
|
|
|
|
|
|
const remappedPackages = {
|
|
|
|
...localPackages,
|
2023-01-20 19:33:19 +02:00
|
|
|
};
|
|
|
|
|
2024-05-21 11:12:20 +02:00
|
|
|
// cSpell:disable
|
|
|
|
// Some packages aren't available in react-native and thus must be polyfilled
|
|
|
|
// For example, this allows us to `import {resolve} from 'path'` rather than
|
2023-07-18 15:58:06 +02:00
|
|
|
// `const { resolve } = require('path-browserify')` ('path-browerify' doesn't have its own type
|
|
|
|
// definitions).
|
2024-05-21 11:12:20 +02:00
|
|
|
// cSpell:enable
|
|
|
|
const polyfilledPackages = ['path'];
|
|
|
|
for (const package of polyfilledPackages) {
|
2023-07-18 15:58:06 +02:00
|
|
|
remappedPackages[package] = path.resolve(__dirname, `./node_modules/${package}-browserify/`);
|
|
|
|
}
|
|
|
|
|
2023-01-20 19:33:19 +02:00
|
|
|
const watchedFolders = [];
|
|
|
|
for (const [, v] of Object.entries(localPackages)) {
|
|
|
|
watchedFolders.push(v);
|
|
|
|
}
|
|
|
|
|
2024-05-21 11:12:20 +02:00
|
|
|
const defaultConfig = getDefaultConfig(__dirname);
|
2024-03-14 21:04:32 +02:00
|
|
|
|
2024-05-21 11:12:20 +02:00
|
|
|
// Metro configuration
|
|
|
|
// https://facebook.github.io/metro/docs/configuration
|
|
|
|
//
|
|
|
|
// @type {import('metro-config').MetroConfig}
|
|
|
|
const config = {
|
2020-11-05 18:58:23 +02:00
|
|
|
transformer: {
|
|
|
|
getTransformOptions: async () => ({
|
|
|
|
transform: {
|
|
|
|
experimentalImportSupport: false,
|
2021-08-09 22:45:41 +02:00
|
|
|
inlineRequires: true,
|
2020-11-05 18:58:23 +02:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
resolver: {
|
2024-03-14 21:04:32 +02:00
|
|
|
assetExts: [
|
|
|
|
...defaultConfig.resolver.assetExts,
|
|
|
|
|
|
|
|
// Allow loading .jpl plugin files
|
|
|
|
'jpl',
|
|
|
|
],
|
|
|
|
|
2023-01-20 19:33:19 +02:00
|
|
|
// This configuration allows you to build React-Native modules and test
|
|
|
|
// them without having to publish the module. Any exports provided by
|
|
|
|
// your source should be added to the "target" parameter. Any import not
|
|
|
|
// matched by a key in target will have to be located in the embedded
|
|
|
|
// app's node_modules directory.
|
2020-11-05 18:58:23 +02:00
|
|
|
//
|
|
|
|
extraNodeModules: new Proxy(
|
2023-01-20 19:33:19 +02:00
|
|
|
// The first argument to the Proxy constructor is passed as "target"
|
|
|
|
// to the "get" method below. Put the names of the libraries
|
|
|
|
// included in your reusable module as they would be imported when
|
|
|
|
// the module is actually used.
|
2020-11-05 18:58:23 +02:00
|
|
|
//
|
2023-07-18 15:58:06 +02:00
|
|
|
remappedPackages,
|
2020-11-05 18:58:23 +02:00
|
|
|
{
|
|
|
|
get: (target, name) => {
|
|
|
|
if (target.hasOwnProperty(name)) {
|
|
|
|
return target[name];
|
|
|
|
}
|
|
|
|
return path.join(process.cwd(), `node_modules/${name}`);
|
|
|
|
},
|
2023-08-22 12:58:53 +02:00
|
|
|
},
|
2020-11-05 18:58:23 +02:00
|
|
|
),
|
|
|
|
},
|
|
|
|
projectRoot: path.resolve(__dirname),
|
2023-01-20 19:33:19 +02:00
|
|
|
watchFolders: watchedFolders,
|
2020-11-05 18:58:23 +02:00
|
|
|
};
|
2024-05-21 11:12:20 +02:00
|
|
|
|
|
|
|
module.exports = mergeConfig(defaultConfig, config);
|