storybookjs / storybook

Storybook is the industry standard workshop for building, documenting, and testing UI components in isolation
https://storybook.js.org
MIT License
83.95k stars 9.21k forks source link

How to make the built output target be es5? #18096

Open southwhale opened 2 years ago

southwhale commented 2 years ago

How to make the built output target be es5? It seems that the default output target is es6, and I can't change it. I have tried many times and I can't find the way to make the ouput target be es5. Please give me some help. Thanks.

Storybook version: 6.4.22 React version: 17.0.2

southwhale commented 2 years ago

I added the code below to main.js, but it did not work.

babel: async (options) => ({
    ...options,
    // any extra options you want to set
    "presets": [
      [
        "@babel/env",
        {
          "targets": {
            "esmodules": true
          }
        }
      ],
      ["@babel/react"]
    ],
    "env": {
      "camo-test": {
        "plugins": [
          [
            "@babel/transform-runtime",
            {
              "regenerator": true
            }
          ],
          "@babel/plugin-syntax-dynamic-import"
        ],
        "presets": [
          [
            "@babel/env",
            {
              "targets": {
                "esmodules": true
              }
            }
          ],
          ["@babel/react"]
        ]
      },
      "test": {
        "plugins": [
          [
            "@babel/transform-runtime",
            {
              "regenerator": true
            }
          ],
          "@babel/plugin-syntax-dynamic-import"
        ],
        "presets": [
          [
            "@babel/env",
            {
              "targets": {
                "esmodules": true
              }
            }
          ],
          ["@babel/react"]
        ]
      }
    }
  }),
burhanuday commented 2 years ago

It is possible to extend storybook's webpack config as documented here - https://storybook.js.org/docs/react/configure/webpack#extending-storybooks-webpack-config you could set the targets property to targets: ["web", "es5"] that should solve the problem