originjs / vite-plugin-federation

Module Federation for vite & rollup
Other
2.39k stars 241 forks source link

Can not read rollup.external when it's type is RegExp #556

Closed AttackXiaoJinJin closed 9 months ago

AttackXiaoJinJin commented 11 months ago

Versions

Reproduction

remote vite.config.js:

build:{
    rollupOptions:{
      external: [/^aaa/]
    }
  },

run build and:

image

THE CODE IS:

https://github.com/originjs/vite-plugin-federation/blob/76e847a9af25f98a3c51afd3c8cf039f6ec5ac23/packages/lib/src/prod/shared-production.ts#L49

get external and use removeNonRegLetter

 inputOptions.external = (inputOptions.external as [])?.filter(
          (item) => {
            return !shareName2Prop.has(removeNonRegLetter(item, NAME_CHAR_REG))
          }
        )

https://github.com/originjs/vite-plugin-federation/blob/76e847a9af25f98a3c51afd3c8cf039f6ec5ac23/packages/lib/src/utils/index.ts#L169

export function removeNonRegLetter(str: string, reg = letterReg): string {
  let needUpperCase = false
  let ret = ''
  for (const c of str) {
    if (reg.test(c)) {
      ret += needUpperCase ? c.toUpperCase() : c
      needUpperCase = false
    } else {
      needUpperCase = true
    }
  }
  return ret
}

removeNonRegLetter first param SHOULD BE string|RegExp

https://rollupjs.org/configuration-options/#external

image