{"id":21937448,"url":"https://github.com/packingjs/packing-template","last_synced_at":"2026-04-09T07:37:49.602Z","repository":{"id":71559720,"uuid":"124255343","full_name":"packingjs/packing-template","owner":"packingjs","description":"Packing Template","archived":false,"fork":false,"pushed_at":"2018-04-08T07:40:52.000Z","size":344,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-27T13:48:18.713Z","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/packingjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"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-03-07T15:25:21.000Z","updated_at":"2018-04-08T07:40:53.000Z","dependencies_parsed_at":"2023-02-24T20:45:12.802Z","dependency_job_id":null,"html_url":"https://github.com/packingjs/packing-template","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/packingjs%2Fpacking-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/packingjs%2Fpacking-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/packingjs%2Fpacking-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/packingjs%2Fpacking-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/packingjs","download_url":"https://codeload.github.com/packingjs/packing-template/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244967633,"owners_count":20539988,"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":"2024-11-29T01:19:49.798Z","updated_at":"2025-12-30T23:47:29.322Z","avatar_url":"https://github.com/packingjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# packing-template\n\n这是 Packing 前端开发工具用来处理网页模版的工具包。本包提供两个方法：\n\n- middleware\n- plugin\n\n这两个方法的参数可以通过下面两种方式传入：\n\n- 在函数调用处通过 `options` 传入。这种方式传入的参数对所有 entry points 都有效。\n- 通过与 `${entry}.js` 同目录的 `${entry}.settings.js` 配置文件传入。这种方式传入的参数仅对单一 entry point 有效。\n\n```js\nimport path from 'path';\n\nexport default {\n  template: path.resolve(__dirname, 'template.html'),\n  title: 'Page A',\n  keywords: 'A AA',\n  description: 'A simple text',\n  attrs: ['img:src', 'link:href', 'script:src'],\n  city: 'Beijing'\n};\n\n```\n\n## middleware\n这是一个 [express](https://expressjs.com) 中间件，提供开发环境下网页自动生成、脚本注入的功能。\n\n### 用法\n```js\nimport Express from 'express';\nimport { middleware } from 'packing-template';\n\nconst app = new Express();\n\nmiddleware(app, appConfig, {\n    template: path.resolve(__dirname, 'template.html'),\n    // inject: 'head',\n    // favicon: 'xxx.png'\n    // charset: 'gb2312'\n});\n```\n\n### 参数\n#### app\n[express](https://expressjs.com) 实例。\n\n#### appConfig\npacking 配置。\n\n#### options\n可选参数：\n\n##### template\n类型: `String`\n\n默认值: `node_modules/packing-template/templates/default.html`\n\n模版文件的绝对路径。\n\n##### inject\n类型: `String`\n\n默认值: `body`\n\n可选值:\n    - body: 插入在 \u003c/body\u003e 标签前面\n    - head:: 插入在 \u003c/head\u003e 标签前面\n\njs脚本注入到 HTML 代码的位置。\n\n是否在网页中插入 favico meta标签。当取值不是 `false` 时，该值表示 favicon 的路径。\n\n##### chunks\n类型: `[String] | null`\n\n默认值: `null`\n\n需要在页面中插入的 chunk 列表。\n\n##### excludeChunks\n类型: `[String] | null`\n\n默认值: `null`\n\n不需要在页面中插入的 chunk 列表。\n\n##### chunksSortMode\n类型: `String`\n\n默认值: `commonChunksFirst`\n\n可选值:\n    - id: 按 chunk id 正序\n    - none: 按 entries 中的顺序\n    - reverse: 按 entries 中的顺序反转\n    - manual: 按 `chunks` 中指定的顺序\n    - commonChunksFirst: 公共包优先\n\nchunk 包在页面中插入的顺序。\n\n##### favicon\n类型: `Boolean | String`\n\n默认值: `false`\n\n是否在网页中插入 favico meta标签。当取值不是 `false` 时，该值表示 favicon 的路径。\n\n##### title\n类型: `String`\n\n默认值: `untitled`\n\n网页标题。\n\n##### charset\n类型: `String`\n\n默认值: `utf-8`\n\n网页使用的字符集。\n\n##### keywords\n类型: `Boolean | String`\n\n默认值: `utf-8`\n\n是否在网页中插入 keywords meta标签。当取值不是 `false` 时，该值表示 keywords 的值。\n\n##### description\n类型: `Boolean | String`\n\n默认值: `utf-8`\n\n是否在网页中插入 description meta标签。当取值不是 `false` 时，该值表示 description 的值。\n\n## plugin\n这是一个 webpack 插件，它在发布时会根据 entry points 文件生成对应的网页文件。\n\n\n### 用法\n```js\nimport Express from 'express';\nimport { middleware } from 'packing-template';\n\nconst app = new Express();\n\nmiddleware(app, appConfig, {\n    template: path.resolve(__dirname, 'template.html'),\n    // inject: 'head',\n    // favicon: 'xxx.png'\n    // charset: 'gb2312'\n});\n```\n\n### 参数\n#### app\n[express](https://expressjs.com) 实例。\n\n#### appConfig\npacking 配置。\n\n#### options\n可选参数：\n\n##### template\n类型: `String`\n\n默认值: `node_modules/packing-template/templates/default.html`\n\n模版文件的绝对路径。\n\n##### inject\n类型: `String`\n\n默认值: `body`\n\n可选值:\n    - body: 插入在 \u003c/body\u003e 标签前面\n    - head: 插入在 \u003c/head\u003e 标签前面\n\njs脚本注入到 HTML 代码的位置。\n\n是否在网页中插入 favico meta标签。当取值不是 `false` 时，该值表示 favicon 的路径。\n\n##### chunks\n类型: `[String] | null`\n\n默认值: `null`\n\n需要在页面中插入的 chunk 列表。\n\n##### excludeChunks\n类型: `[String] | null`\n\n默认值: `null`\n\n不需要在页面中插入的 chunk 列表。\n\n##### chunksSortMode\n类型: `String`\n\n默认值: `commonChunksFirst`\n\n可选值:\n    - id: 按 chunk id 正序\n    - none: 按 entries 中的顺序\n    - reverse: 按 entries 中的顺序反转\n    - manual: 按 `chunks` 中指定的顺序\n    - commonChunksFirst: 公共包优先\n\nchunk 包在页面中插入的顺序。\n\n##### favicon\n类型: `Boolean | String`\n\n默认值: `false`\n\n是否在网页中插入 favico meta标签。当取值不是 `false` 时，该值表示 favicon 的路径。\n\n##### title\n类型: `String`\n\n默认值: `untitled`\n\n网页标题。\n\n##### charset\n类型: `String`\n\n默认值: `utf-8`\n\n网页使用的字符集。\n\n##### keywords\n类型: `Boolean | String`\n\n默认值: `utf-8`\n\n是否在网页中插入 keywords meta标签。当取值不是 `false` 时，该值表示 keywords 的值。\n\n##### description\n类型: `Boolean | String`\n\n默认值: `utf-8`\n\n是否在网页中插入 description meta标签。当取值不是 `false` 时，该值表示 description 的值。\n\n##### attrs\n类型: `Array`\n\n默认值: `[img:src, link:href]`\n\n网页文件中需要在编译时替换为 `_hash` 的标签属性。格式为 `tag:attribute` 。如果想对所有标签的某个属性替换，请使用 `*` 代替 `tag`，如所有标签的 `src` 属性都需要替换，则使用 `*:src`。\n\n##### filename\n类型: `String`\n\n默认值: `[path][name]_[hash:8].[ext]`\n\n模版中命中的静态文件编译输出的文件名。\n\n\n## pug 模版支持的一些约定\n\n`pug` 模版灵活的语法，网页可以被拆分成很多没有规律的代码片段，这种复杂的结构导致了自动注入代码变得很困难，为了简化自动注入代码的逻辑，现对 `pug` 做以下约定：\n\n- 模版分为两类\n    - `layout` 布局母模版\n    - `pages` 页面入口模版，可以是通用模版，也可以是与 entry points 一一对应的模版（为了兼容 packing v3 以下版本）\n- layout 母模版必须包含以下 `block`\n    - `meta`: 自动注入的 `favico`、`keywords`、`description` 会 append 在该代码末尾\n    - `title`: 自动注入的 `title` 会替换默认网页标题\n    - `style`: 自动注入的 `CSS` 样式表会 append 在该代码末尾\n    - `script`: 自动注入的 `javascript` 脚本会 append 在该代码末尾\n- 使用 `extends` 方式从母模版页面继承入口页面\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpackingjs%2Fpacking-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpackingjs%2Fpacking-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpackingjs%2Fpacking-template/lists"}