What are the two uses of import?

usage one:

// main.js
import bar from "bar.js"
import "foo.js"
console.log(bar)

//foo.js
import bar from "bar.js"
bar.foo = "foo"

//bar.js
export default bar

usage 2:

// main.js
import bar from "foo.js"
console.log(bar)

//foo.js
import bar from "bar.js"
bar.foo = "foo"
export default bar

//bar.js
export default bar

what are the main differences between the two packaged webpack? How should I choose?

Oct.11,2021

there should be no difference. Webpack loads import in a certain order when packing. It will not be loaded repeatedly, as long as it does not refer to each other

.
Menu