How to implement import react from 'react' / import vue form' vue'

import vue from "vue"

The "vue" after

is the name of the package under node_modules, but how do you find
from this package and automatically reference it to dist/vue.js? is it done by webpack or specified by the esmodule specification?


refer to https://www.cnblogs.com/yanze.


package.json

clipboard.png


this is the convention of the node module system, and packaging tools such as webpack follow this convention.


if the relative path or absolute path is not used in import, node will go to the node_modules/ folder by default to find it.
as for the referenced js node_module/vue/package.json file

{
    ...
    "main": "dist/vue.runtime.common.js" // main
    ...
}

  1. import of nodejs currently only supports .mjs .
  2. from script of package.json , we can see that npm run dev runs node build/dev-server.js command. From dev-server.js code, we can see that webpackConfig is used. From webpack.base.conf configuration, we can see that resolveLoader defines node_modules directory, so we will look for vue of node_modules directory. This part belongs to nodejs .
  3. 2 uses a project created with webpack . vue also has a project created without webpack . The deduction logic is the same. See for yourself.

is written in the entry main in package.json

Menu