{"id":17516895,"url":"https://github.com/ahyiru/pack","last_synced_at":"2025-04-09T11:09:46.968Z","repository":{"id":95900267,"uuid":"602005426","full_name":"ahyiru/pack","owner":"ahyiru","description":"@huxy/pack 是一个项目构建工具，集成了 esbuild、eslint、stylelint、jest、commitlint、husky、standard-version、postcss、prettier，提供开发环境、构建打包、本地启动服务、环境配置、代理配置等功能。","archived":false,"fork":false,"pushed_at":"2024-12-07T03:49:44.000Z","size":147,"stargazers_count":54,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-20T03:03:37.162Z","etag":null,"topics":["commitlint","esbuild","eslint","husky","jest","nodejs","postcss","stylelint","webpack"],"latest_commit_sha":null,"homepage":"","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/ahyiru.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":"2023-02-15T09:49:11.000Z","updated_at":"2024-12-07T03:49:48.000Z","dependencies_parsed_at":"2023-06-18T21:56:34.255Z","dependency_job_id":"aa874853-e8ed-4af7-99d4-44588cca2d06","html_url":"https://github.com/ahyiru/pack","commit_stats":{"total_commits":237,"total_committers":1,"mean_commits":237.0,"dds":0.0,"last_synced_commit":"239976f27f43f14c375836347123dedd5a2bca6e"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahyiru%2Fpack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahyiru%2Fpack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahyiru%2Fpack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahyiru%2Fpack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahyiru","download_url":"https://codeload.github.com/ahyiru/pack/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248027408,"owners_count":21035594,"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":["commitlint","esbuild","eslint","husky","jest","nodejs","postcss","stylelint","webpack"],"created_at":"2024-10-20T08:10:51.605Z","updated_at":"2025-04-09T11:09:46.927Z","avatar_url":"https://github.com/ahyiru.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## @huxy/pack\n\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/ahyiru/pack/blob/develop/LICENSE)\n[![npm version](https://img.shields.io/npm/v/@huxy/pack.svg)](https://www.npmjs.com/package/@huxy/pack)\n[![npm](https://img.shields.io/npm/dt/@huxy/pack)](https://www.npmjs.com/package/@huxy/pack)\n[![](https://img.shields.io/badge/blog-ihuxy-blue.svg)](http://ihuxy.com/)\n\n`@huxy/pack` 是一个项目构建工具，集成了 `esbuild`、`eslint`、`stylelint`、`jest`、`commitlint`、`husky`、`standard-version`、`postcss`、`prettier`，提供开发环境、构建打包、本地启动服务、环境配置、代理配置等功能。使用简单方便，功能齐全，配置灵活，可自己添加需要的功能插件。\n\n运行时会自动生成插件配置文件，如 `babel.config.js` 文件等，可自行修改覆盖。\n\n生成项目配置文件 `.huxy/app.configs.js` ，用户自行配置即可。\n\n### app.configs\n\n用户环境配置：\n\n```javascript\nconst app = {\n  // entry: 'app', // 项目入口目录，默认 app 文件夹\n  // HOST: 'http://localhost', // 本地运行\n  PORT: 8080, // 本地开发环境端口\n  PROD_PORT: 8081, // 本地生产环境端口\n  PUBLIC_DIR: 'public', // public 文件路径\n  BUILD_DIR: 'build', // 构建产物路径\n  DEV_ROOT_DIR: '/', // 开发环境 basepath\n  // PROD_ROOT_DIR: '/huxy', // 生产环境 basepath\n  projectName: 'XX平台', // 名称，页面初始化 title\n  /* PROXY: { // 代理配置\n    url: 'http://127.0.0.1:9000',\n    prefix: '/api',\n  }, */\n  envConfigs: { // 全局环境变量\n    name: '项目名',\n    _id: '其它属性',\n  },\n};\n\nconst webpack = { // webpack 配置\n  // ... // 基础配置\n  dev: { // 开发环境配置\n    // ...\n  },\n  prod: { // 生产环境配置\n    // ...\n  },\n};\n\nconst nodeServer = app =\u003e { // 本地 nodejs 服务配置\n  app.get('/local/test', (req, res, next) =\u003e {\n    console.log(req);\n  });\n};\n\n\nexport default {\n  app,\n  webpack,\n  nodeServer,\n};\n\n// 例如\n\nexport default {\n  app,\n  webpack: (rootPath, appPath) =\u003e ({\n    resolve: {\n      alias: {\n        '@huxy': `${rootPath}/playground/huxy`,\n      },\n    },\n    prod: {\n      copy: [ // 拷贝文件\n        {\n          from: `${appPath}/public/robots.txt`,\n          to: `${appPath}/build/robots.txt`,\n        },\n      ],\n      buildConfigs: {\n        target: 'es2018',\n        minify: true,\n      },\n    },\n  }),\n};\n```\n\n- copy：构建完成拷贝文件或文件夹。\n- buildConfigs：打包资源配置，见 esbuild 配置项。\n\n`webpack` 配置项可以是一个配置对象，也可以是一个带有 `rootDir` 和 `appPath` 的回调函数。当要使用到路径时，请使用回调函数来获取根目录路径和 `app` 路径。\n\n### 运行命令\n\n```\n\"start\": \"pack start\",\n\"build\": \"pack run build\",\n\"analyze\": \"pack run analyze\",\n\"server\": \"pack run server\",\n\"test\": \"pack run test\",\n```\n\n其它 `npm` 命令：\n\n```\n\"eslint\": \"pack eslint 'app/**/*.{js,jsx}'\", // 或直接使用 eslint\n\"eslint-common\": \"eslint 'common/**/*.{js,jsx}'\",\n\"stylelint\": \"stylelint 'app/**/*.{css,less}'\",\n\"lint-fix\": \"eslint --fix 'app/**/*.{js,jsx}' \u0026\u0026 stylelint --fix 'app/**/*.{css,less}'\",\n\"prettier\": \"prettier 'app/**/*' --write --ignore-unknown\",\n\"release\": \"standard-version\"\n```\n\n### 使用\n\n新建一个项目，创建 `public` 和 `app` 目录。\n\n- public：静态资源目录，存放 `index.html` 和 `favicon` 等。可使用 `app.configs` 里面的 `PUBLIC_DIR` 来配置路径，默认 `public ` 放在 `app` 目录里面。\n- app：存放项目代码文件，也是入口文件夹。可自己命名，如 `src`，在配置文件里配置 `entry: 'src'` 即可。\n\n安装 `@huxy/pack`\n\n```\nnpm i -D @huxy/pack\n```\n\n然后在 `package.json` 里面创建上面运行命令里的 `scripts` ，就可运行了。\n\n***版本 0.6+ 使用了 `esmodule`，只需在 `package.json` 里面设置 `\"type\": \"module\"` 即可。***","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahyiru%2Fpack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahyiru%2Fpack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahyiru%2Fpack/lists"}