JavaScript/vite/组件构建:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
Kangkk​(留言 | 贡献)
第11行: 第11行:
const entries = new Map<string, string>()
const entries = new Map<string, string>()
const GLOB_PATH = path.resolve(__dirname, 'src/**/*.ts')
const GLOB_PATH = path.resolve(__dirname, 'src/**/*.ts')
const OUTPUT_PATH = path.join(__dirname, 'bundle')


for (const file of glob.sync(GLOB_PATH)) {
for (const file of glob.sync(GLOB_PATH)) {
   const filenameWidthExt = file.split('/').at(-1)
   const filenameWidthExt = file.split('/').at(-1)
   const filename = filenameWidthExt?.split('.')[0]
   const filename = filenameWidthExt?.split('.')[0]
   if (!filename) continue;
   if (!filename) continue


   const absolutePath = file.slice(0, file.length - filenameWidthExt.length)
   const absolutePath = file.slice(0, file.length - filenameWidthExt.length)
   const relativePath = absolutePath.replace(new RegExp(path.join(__dirname, 'src'),'g'),'')
   const relativePath = absolutePath.replace(new RegExp(path.join(__dirname, 'src/'), 'g'), '')


   entries.set(`${relativePath}/${filename}`, fileURLToPath(new URL(file, import.meta.url)))
  console.log('absolutePath', absolutePath)
  console.log('relativePath', relativePath)
  console.log('key', path.join(relativePath, filename))
  console.log('value', fileURLToPath(new URL(file, import.meta.url)))
 
   entries.set(path.join(relativePath, filename), fileURLToPath(new URL(file, import.meta.url)))
}
}


// Add any additional entries
// Add any additional entries
entries.set('index', './src/index.ts')
// entries.set('index', './src/index.ts')


// in the defineConfig
// in the defineConfig