{"id":22770727,"url":"https://github.com/fupengl/learn-webpack","last_synced_at":"2026-05-16T06:36:55.782Z","repository":{"id":154934104,"uuid":"160027834","full_name":"fupengl/learn-webpack","owner":"fupengl","description":"learn-webpack","archived":false,"fork":false,"pushed_at":"2018-12-18T07:53:23.000Z","size":9156,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T11:43:38.335Z","etag":null,"topics":["webpack","webpack4"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fupengl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-12-02T08:28:55.000Z","updated_at":"2019-01-06T11:27:40.000Z","dependencies_parsed_at":"2023-05-02T23:00:41.447Z","dependency_job_id":null,"html_url":"https://github.com/fupengl/learn-webpack","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fupengl/learn-webpack","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fupengl%2Flearn-webpack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fupengl%2Flearn-webpack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fupengl%2Flearn-webpack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fupengl%2Flearn-webpack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fupengl","download_url":"https://codeload.github.com/fupengl/learn-webpack/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fupengl%2Flearn-webpack/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33092728,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-16T04:41:52.686Z","status":"ssl_error","status_checked_at":"2026-05-16T04:41:52.009Z","response_time":115,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["webpack","webpack4"],"created_at":"2024-12-11T15:37:55.862Z","updated_at":"2026-05-16T06:36:55.766Z","avatar_url":"https://github.com/fupengl.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Learn Webpack\n\n![webpack](/assets/webpack.png)\n\n[Webpack](https://webpack.js.org/) 是一个现代 JavaScript 应用程序的静态模块打包器(static module bundler)。在 webpack 处理应用程序时，它会在内部创建一个依赖图(dependency graph)，用于映射到项目需要的每个模块，然后将所有这些依赖生成到一个或多个bundle\n\n### 为什要使用WebPack\n现今的很多网页其实可以看做是功能丰富的应用，它们拥有着复杂的JavaScript代码和一大堆依赖包。为了简化开发的复杂度，前端社区涌现出了很多好的实践方法\n\n* 模块化，让我们可以把复杂的程序细化为小的文件;\n* 类似于TypeScript这种在JavaScript基础上拓展的开发语言：使我们能够实现目前版本的JavaScript不能直接使用的特性，并且之后还能转换为JavaScript文件使浏览器可以识别；\n* Scss，less等CSS预处理器\n* ...\n\n这些改进确实大大的提高了我们的开发效率，但是利用它们开发的文件往往需要进行额外的处理才能让浏览器识别,而手动处理又是非常繁琐的，这就为WebPack类的工具的出现提供了需求。\n\n### WebPack和Grunt以及Gulp相比有什么特性\n* 其实Webpack和另外两个并没有太多的可比性，Gulp/Grunt是一种能够优化前端的开发流程的工具，而WebPack是一种模块化的解决方案，不过Webpack的优点使得Webpack在很多场景下可以替代Gulp/Grunt类的工具。\n* Grunt和Gulp的工作方式是：在一个配置文件中，指明对某些文件进行类似编译，组合，压缩等任务的具体步骤，工具之后可以自动替你完成这些任务。\n* Webpack的工作方式是：把你的项目当做一个整体，通过一个给定的主文件（如：index.js），Webpack将从这个文件开始找到你的项目的所有依赖文件，使用loaders处理它们，最后打包为一个（或多个）浏览器可识别的JavaScript文件。\n* 如果实在要把二者进行比较，Webpack的处理速度更快更直接，能打包更多不同类型的文件。\n\n### webpack.config.js配置项简介\n\n* Entry：入口文件配置，Webpack 执行构建的第一步将从 Entry 开始，完成整个工程的打包。\n* Module：模块，在`Webpack`里一切皆模块，`Webpack`会从配置的`Entry`开始递归找出所有依赖的模块，最常用的是`rules`配置项，功能是匹配对应的后缀，从而针对代码文件完成格式转换和压缩合并等指定的操作。\n* Loader：模块转换器，用于把模块原内容按照需求转换成新内容，这个是配合`Module`模块中的`rules`中的配置项来使用。\n* Plugins：扩展插件，在`Webpack`构建流程中的特定时机注入扩展逻辑来改变构建结果或做你想要的事情。\n* Output：输出结果，在`Webpack`经过一系列处理并得出最终想要的代码后输出结果，配置项用于指定输出文件夹，默认是`./dist`。\n* DevServer：用于配置开发过程中使用的本机服务器配置，属于`webpack-dev-server`这个插件的配置项。\n* Resolve：用于更改模块的解析方式，例如增加默认补全文件扩展`extensions`支持`.coffce`,`.ts`，设置`alise`。\n\n### webpack打包流程简介\n\n- 根据传入的参数模式(`development` | `production`)来加载对应的默认配置。\n- 在`entry`里配置的`module`开始递归解析`entry`所依赖的所有`module`。\n- 每一个`module`都会根据`rules`的配置项去寻找用到的`loader`,接受所配置的`loader`的处理。\n- 以`entry`中的配置对象为分组，每一个配置入口和其对应的依赖文件最后组成一个代码块文件(chunk)并输出。\n- 整个流程中`webpack`会在恰当的时机执行`plugin`的逻辑，来完成自定义的插件逻辑。\n\n### Example\n* [Example 1: hello world!](https://github.com/fupengl/learn-webpack/tree/master/examples/1.hellow-word)\n* [Example 2: Multiple entries](https://github.com/fupengl/learn-webpack/tree/master/examples/2.multiple-entries)\n* [Example 3: Loader](https://github.com/fupengl/learn-webpack/tree/master/examples/3.loader)\n* [Example 4: Plugin](https://github.com/fupengl/learn-webpack/tree/master/examples/4.plugin)\n* [Example 3: Dev Server](https://github.com/fupengl/learn-webpack/tree/master/examples/5.dev-server)\n* [Example 3: Common Chunk](https://github.com/fupengl/learn-webpack/tree/master/examples/6.common-chunk)\n\n### 文档链接\n* [segmentfault webpak](https://segmentfault.com/a/1190000006178770?utm_source=tag-newest)\n* [splitChunk](https://juejin.im/post/5af1677c6fb9a07ab508dabb)\n* [webpack plugin](https://juejin.im/entry/5a4cb7906fb9a04500037399)\n* [webpack 流程](http://taobaofed.org/blog/2016/09/09/webpack-flow/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffupengl%2Flearn-webpack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffupengl%2Flearn-webpack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffupengl%2Flearn-webpack/lists"}