Skip to content

Commit 993c60e

Browse files
committed
vue源码初始化
0 parents  commit 993c60e

File tree

8 files changed

+1662
-0
lines changed

8 files changed

+1662
-0
lines changed

.babelrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"presets": [
3+
"@babel/preset-env"
4+
]
5+
}

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.DS_Store
2+
node_modules
3+
*.log
4+
explorations
5+
TODOs.md
6+
RELEASE_NOTE*.md
7+
.vscode
8+
dist
9+
temp
10+
types/v3-generated.d.ts

package-lock.json

+1,578
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "vue-code",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"type": "module",
7+
"scripts": {
8+
"dev": "rollup -cw"
9+
},
10+
"keywords": [],
11+
"author": "",
12+
"license": "ISC",
13+
"devDependencies": {
14+
"@babel/core": "^7.20.12",
15+
"@babel/preset-env": "^7.20.2",
16+
"rollup": "^3.9.1",
17+
"rollup-plugin-babel": "^4.4.0"
18+
}
19+
}

rollup.config.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// rollup默认可以导出一个对象,作为打包配置文件
2+
import babel from "rollup-plugin-babel"
3+
export default {
4+
input: './src/index.js',//入口
5+
output: {
6+
file: './dist/vue.js',//出口
7+
name: 'Vue',//global.Vue
8+
format: 'umd',//规范
9+
sourcemap: true//可以调试源代码
10+
},
11+
plugins: [
12+
babel({
13+
exclude: 'node_modules/**'//排除node_modules
14+
})
15+
]
16+
17+
}

src/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { initMixin } from "./init"
2+
3+
function Vue (options) {//用户选项
4+
debugger
5+
this._init(options)
6+
}
7+
initMixin(Vue)
8+
export default Vue

src/init.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { initState } from "./state"
2+
3+
export function initMixin (Vue) {//给vue添加init方法
4+
Vue.prototype._init = function (options) {//用于初始化操作
5+
const vm = this
6+
vm.$options = options
7+
8+
initState(vm)
9+
}
10+
}

src/state.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export function initState (vm) {
2+
const ops = vm.$options
3+
if (ops.data) {
4+
initData(vm)
5+
}
6+
7+
}
8+
9+
function initData (vm) {
10+
let data = vm.$options.data
11+
typeof data === 'function' ? data.call(vm) : data
12+
debugger
13+
console.log(data)
14+
15+
}

0 commit comments

Comments
 (0)