问题
I'm using webpack + vue-loader to create vuejs app. I have multiple .vue
files for components. When I write something like this:
import _ from 'lodash'
inside the script
part of ComponentA.vue
and ComponentB.vue
, does this create two separate copies of lodash or does it simply import a reference?
回答1:
Importing an ES6 module, or any part of an ES6 module, produces a binding.
CommonJS modules export values, while ES6 modules export immutable bindings. This blog post explains what that means.
[ Source: ES6 Module Exports ]
So the answer is no, it does not create a copy of the exports. The module is initialised once and each import will receive a reference to the same value.
来源:https://stackoverflow.com/questions/37965902/does-import-create-a-new-copy-of-imported-library