vite-plugin / vite-plugin-commonjs

A pure JavaScript implementation for CommonJs
MIT License
105 stars 16 forks source link

fix: dynamic require #42

Closed plainnany closed 8 months ago

plainnany commented 11 months ago

fix: issue27 demo: https://github.com/plainnany/vite-plugin-commonjs/tree/dynamic-demo/example

yejimeiming commented 11 months ago

Mybe the following code is better.

record.dynaimc = {
  importee: [],
- runtimeName: `__matchRequireRuntime${counter}__`,
+ runtimeName: `__matchRequireRuntime${counter++}__`,
  runtimeFn: '', // to be immediately set
}
plainnany commented 11 months ago

Mybe the following code is better.

record.dynaimc = {
  importee: [],
- runtimeName: `__matchRequireRuntime${counter}__`,
+ runtimeName: `__matchRequireRuntime${counter++}__`,
  runtimeFn: '', // to be immediately set
}

@yejimeiming counter++ may be used many times,consider using const counter3 = counter++