How to append extension in metro.config.js for Metro Bundler?
Found the answer on how to include the defaults here: https://stackoverflow.com/a/55118654/844907.
/**
* Metro configuration for React Native
* https://github.com/facebook/react-native
*
* @format
*/
// get defaults assetExts array
const defaultAssetExts = require("metro-config/src/defaults/defaults").assetExts;
module.exports = {
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false,
},
}),
},
resolver: {
assetExts: [
...defaultAssetExts, // <- array spreading defaults
'md'
]
}
};
Other way you could do this is use the same syntax as react-native-svg-transformer
- Make metro.config.js asynchronous
- call the getDefaultConfig
- Pull off the assetExts key
Example
const { getDefaultConfig } = require('metro-config')
module.exports = (async () => {
const {
resolver: { assetExts },
} = await getDefaultConfig()
return {
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false,
},
}),
},
resolver: {
assetExts: [...assetExts, 'md'],
},
}
})()