{"id":27995568,"url":"https://github.com/chokcoco/miniwebpack","last_synced_at":"2025-05-08T20:33:39.288Z","repository":{"id":42928069,"uuid":"241612151","full_name":"chokcoco/miniWebpack","owner":"chokcoco","description":"简易版 Webpack 打包工具，便于理解整个 Webpack 打包链路。","archived":false,"fork":false,"pushed_at":"2023-01-05T07:43:23.000Z","size":96,"stargazers_count":13,"open_issues_count":5,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-03-01T18:35:46.980Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chokcoco.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-19T12:07:44.000Z","updated_at":"2022-04-18T05:57:45.000Z","dependencies_parsed_at":"2023-02-03T19:01:07.375Z","dependency_job_id":null,"html_url":"https://github.com/chokcoco/miniWebpack","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chokcoco%2FminiWebpack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chokcoco%2FminiWebpack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chokcoco%2FminiWebpack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chokcoco%2FminiWebpack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chokcoco","download_url":"https://codeload.github.com/chokcoco/miniWebpack/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253145432,"owners_count":21861233,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-08T20:33:36.251Z","updated_at":"2025-05-08T20:33:38.795Z","avatar_url":"https://github.com/chokcoco.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## miniWebpack\n\n## Dependencies \n```\n{\n  \"@babel/core\": \"^7.8.4\",\n  \"@babel/parser\": \"^7.8.4\",\n  \"@babel/preset-env\": \"^7.8.4\",\n  \"@babel/traverse\": \"^7.8.4\"\n}\n```\n\n### @babel/parser\n\n编译代码拿到 AST。\n\n```javascript\nvar fs = require('fs');\nvar parser = require('@babel/parser');\n\nfunction entryRead(pathname) {\n  const entryContent = fs.readFileSync(pathname, 'utf-8');\n\n  let AST = parser.parse(entryContent, {\n    sourceType: \"module\",\n  });\n}\n\nentryRead('./src/index.js');\n```\n\n### @babel/traverse\n\nBabel Traverse（遍历）模块维护了整棵树的状态，并且负责替换、移除和添加节点。\n\n我们使用 @babel/traverse 递归（或者使用队列）拿到所有依赖文件信息数组。\n\n```javascript\nconst fs = require('fs');\nconst parser = require('@babel/parser');\nconst traverse = require('@babel/traverse').default;\n\nconst entryContent = fs.readFileSync(filename, 'utf-8');\n\nlet AST = parser.parse(entryContent, {\n  sourceType: \"module\",\n});\n\n// 依赖项\nconst dependencies = [];\n\n// visitor\ntraverse(AST, {\n  ImportDeclaration: (path) =\u003e {\n    const node = path.node;\n    const value = node.source.value;\n\n    dependencies.push(value);\n  }\n})\n```\n\n### @babel/core 、@babel/preset-env\n\n将 ES6 编译的的 AST 代码转回 ES5 语法代码。’\n\n## Run\n\n```\n$ node webpack.config.js\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchokcoco%2Fminiwebpack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchokcoco%2Fminiwebpack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchokcoco%2Fminiwebpack/lists"}