No estoy seguro de por qué esto no funciona. solía tener
// file 1 import Box from '@/components/Box' import Popup from '@/components/Popup' const MDXComponents = { Box, Popup } // using MDXComponents somewhere in file 1Ahora quiero subcontratar el objeto MDXComponents, ya que se está volviendo demasiado grande. Así que creé un nuevo archivo:
// file 2 import Box from '@/components/Box' import Popup from '@/components/Popup' export default { Box, Popup }Y luego de vuelta en el archivo 1 hago:
// file 1 import * as MDXComponents from './file2' // using MDXComponents somewhere in file 1No me deja hacer esto, pero no estoy seguro de por qué.
Cuando haces esto:
export default { Box, Popup };Establece la exportación predeterminada a un nuevo objeto que tiene 2 propiedades. Necesitarías importar así:
import MDXComponents from './file2'; // And then destructure the object like any normal object. // You can't do import {} in this case, you get the full object. const { Box } = MDXComponents;Cuando haces esto:
export { Box, Popup };Crea dos exportaciones con nombre que puede importar así:
// import all named exports import * as MDXComponents from './file2'; // or just one individually import { Box } from './file2';Para este caso de uso también hay un atajo :
export { default as Box } from '@/components/Box'; export { default as Popup } from '@/components/Popup'; // If a module has named exports (not just a default export) // and you want to export them all: export * from 'some-module'; // Or just some: export { someOtherThing } from '@/components/Box'; export { default as Popup, someOtherThing } from '@/components/Popup';