elderfo / react-native-storybook-loader

An automatic story loader for react-native-storybooks
https://github.com/elderfo/react-native-storybook-loader
MIT License
299 stars 27 forks source link

Compatibility with RN 0.59 "inlineRequires" #65

Open jamsch opened 5 years ago

jamsch commented 5 years ago

React Native 0.59's Metro Bundler adds a new file: metro.config.js which includes the options:

module.exports = {
  transformer: {
    getTransformOptions: async () => ({
      transform: {
        experimentalImportSupport: true,
        inlineRequires: true,
      },
    }),
  },
};

With inlineRequires enabled, require(...) calls with default exports need to chain .default to the call. For example this would change the loadStories requires() from:

function loadStories() {
  require("../src/components/ui/Button/Button.story");
  require("../src/components/ui/Grid/Grid.story");
  require("../src/components/ui/PopupModal/PopupModal.story");
}

to:

function loadStories() {
  require("../src/components/ui/Button/Button.story").default;
  require("../src/components/ui/Grid/Grid.story").default;
  require("../src/components/ui/PopupModal/PopupModal.story").default;
}