rsnext/packages/next/build/webpack/loaders/utils.ts
Jiachi Liu 4bfcf8345c
enhance: detect ESM by ast type (#35627)
Simplify the esmodule detection. If there's any import/exprt usage, it will return `Module` in ast.type otherwise `Script` when `isModule` is set to `"unknown"`
2022-03-28 11:34:32 +00:00

13 lines
375 B
TypeScript

export function buildExports(moduleExports: any, isESM: boolean) {
let ret = ''
Object.keys(moduleExports).forEach((key) => {
const exportExpression = isESM
? `export ${key === 'default' ? key : `const ${key} =`} ${
moduleExports[key]
}`
: `exports.${key} = ${moduleExports[key]}`
ret += exportExpression + '\n'
})
return ret
}