fengxinming / vite-plugins

Some custom plugins for vitejs.
https://fengxinming.github.io/vite-plugins/
MIT License
70 stars 6 forks source link

vite-plugin-external doesn't make sense #15

Closed matthew-dean closed 1 year ago

matthew-dean commented 1 year ago

You'd think that the setup for vite-plugin-external was straightforward, but the documentation is completely opaque:

    createExternal({
      externals: {
        react: 'React'
      }
    }),

What is React supposed to represent? Is this a name that's used somewhere? Presumably, react is the package, so it's not clear why it isn't: externals: ['react'] like a Rollup plugin would be. The documentation doesn't identify what these do or how this will affect the packaging.

When it gets here:

development: {
        externals: {
          react: '$linkdesign.React'
        }
      }

Now this makes even less sense. What is $linkdesign.React?? What does this do? Is this assigning something? To what? And why?

fengxinming commented 1 year ago

@matthew-dean I'm sorry to confuse you, but in some situations of daily development, we can't use local react. For example, the application I'm currently developing is a sub-application, and I use external react which is from a main application. $linkdesign.React means window.$linkdesign.React that is external react, so the vite-plugin-external makes sense.