Handle tree-shaking of unused code in Forge bundler

XMLWordPrintable

      The bundler doesn’t appear to properly remove unused code.

       

      For example… 

       

      helpers.jsx (utility helpers)

       

      import

      Unknown macro: {storage}

      from @forge/api

      export const foo = () =>

      Unknown macro: {   // this helper function only used in frontend   return "hello" }

       

      export const bar = () =>

      Unknown macro: {   // this helper function only used in backend    return storage.get('thing') }

       

      index.jsx (frontend)

       

      import * as Helpers from './helpers'

       

      const App = () =>

      Unknown macro: {   Helpers.foo() }

       

      resolver.js (backend)

       

      import * as Helpers from './helpers'

       

      resolver.define('do', (req)) =>

      Unknown macro: {   Helpers.bar() }

      )

       

      What the Forge bundler should do is recognise that @forge/api here is only being used in the backend resolver. But instead it seems to bundle everything and thus throws an error because it assumes you’re trying to also use that package in the frontend. I think this explains most of the CDAC posts regarding the non-descriptive errors.

            Assignee:
            Joe Clark
            Reporter:
            Vicky Hu
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: