vueTransformerPlugin.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. var semver = require('semver');
  2. var vueNativeScripts = require("vue-native-scripts");
  3. var reactNativeVersionString = require("react-native/package.json").version;
  4. var reactNativeMinorVersion = semver(reactNativeVersionString).minor;
  5. if (reactNativeMinorVersion >= 59) {
  6. upstreamTransformer = require("metro-react-native-babel-transformer");
  7. } else if (reactNativeMinorVersion >= 56) {
  8. upstreamTransformer = require("metro/src/reactNativeTransformer");
  9. } else if (reactNativeMinorVersion >= 52) {
  10. upstreamTransformer = require("metro/src/transformer");
  11. } else if (reactNativeMinorVersion >= 47) {
  12. upstreamTransformer = require("metro-bundler/src/transformer");
  13. } else if (reactNativeMinorVersion === 46) {
  14. upstreamTransformer = require("metro-bundler/build/transformer");
  15. } else {
  16. // handle RN <= 0.45
  17. var oldUpstreamTransformer = require("react-native/packager/transformer");
  18. upstreamTransformer = {
  19. transform({ src, filename, options }) {
  20. return oldUpstreamTransformer.transform(src, filename, options);
  21. }
  22. };
  23. }
  24. var vueExtensions = ["vue"]; // <-- Add other extensions if needed.
  25. module.exports.transform = function({ src, filename, options }) {
  26. if (vueExtensions.some(ext => filename.endsWith("." + ext))) {
  27. return vueNativeScripts.transform({ src, filename, options });
  28. }
  29. return upstreamTransformer.transform({ src, filename, options });
  30. };