lucas-create-template
v1.0.18
Published
### 问题
Downloads
21
Readme
cli-demo
问题
ES Module 的形式 是不可以导入 JSON 文件的,但是可以通过以下进行操作
import pkg from "./package.json" assert { type: "json" } 这可以使用
还可以通过读取文件的形式 进行操作
import.meta.url ESM模块化中的属性 用于获取当前模块文件的 URL 的绝对地址,只可以支持在 ESM 的模块环境中使用
__dirname 获取当前模块所在目录的绝对地址, 它是由NodeJs在每一个模块注入的特殊变量 只可以在commonjs模块中使用
process.cwd() cwd ' current working directory' 当前工作目录
vue create vite-app --force 其实 --force 也就是 --force true 的简写
vue 主命令 create command vite-app command 的参数 --force 叫做 option
我们在命令行输入的 npm i -g xxxx 都会安装在 /Users/chenmingming/.nvm/versions/node/v16.17.1/lib/node_modules/xxxx 里面
提问 我输入了 vue create vite-app 到底是怎么运行的呢?????
- 解析 vue ,然后开始寻找 vue ---> which vue
- 为什么安装的是 @vue/cli 后添加的命令确实 vue
第一步: 通过 which 命令 which vue 查看安装的路径, /Users/chenmingming/.nvm/versions/node/v16.17.1/bin/vue
可以查看 vue ---> ../lib/node_modules/@vue/cli/bin/vue.js
然后查看 /lib/node_modules/@vue/cli 可以得到 package.json 文件中的 bin 字段
"bin": {
"vue": "bin/vue.js"
},
- 全局安装 @vue/cli 发生了什么
第一步 会将该包下载到 node_modules 里面,全局的话
- 为什么 vue 指向的是一个 js 文件,我们却可以通过 vue 的命令去执行它
问题
自己创建一个 xxx.js 文件,在终端是执行不了的 为什么? 因为没有解释器 .js ---> node
但是 vue.js 是可以执行 为什么???? 因为 ---> #!/usr/bin/env node