{"id":27118405,"url":"https://github.com/suconghou/air","last_synced_at":"2025-06-24T13:09:18.055Z","repository":{"id":57174979,"uuid":"45099705","full_name":"suconghou/air","owner":"suconghou","description":"serve static files in the air","archived":false,"fork":false,"pushed_at":"2023-10-11T10:48:15.000Z","size":329,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-09T01:06:01.747Z","etag":null,"topics":["css","eslint","html","javascript","less","prettier"],"latest_commit_sha":null,"homepage":"","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/suconghou.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-10-28T08:47:59.000Z","updated_at":"2023-10-11T06:02:10.000Z","dependencies_parsed_at":"2024-11-15T21:02:05.237Z","dependency_job_id":"3384256e-3de8-4bb1-a78d-e78cee9d3980","html_url":"https://github.com/suconghou/air","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/suconghou/air","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suconghou%2Fair","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suconghou%2Fair/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suconghou%2Fair/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suconghou%2Fair/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/suconghou","download_url":"https://codeload.github.com/suconghou/air/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suconghou%2Fair/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261682921,"owners_count":23193677,"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":["css","eslint","html","javascript","less","prettier"],"created_at":"2025-04-07T07:57:45.057Z","updated_at":"2025-06-24T13:09:18.029Z","avatar_url":"https://github.com/suconghou.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# serve static files in the air\n\n在线解析压缩合并Less,打包压缩Javascript.\n\n\n# 安装\n`npm install airs -g`\n\n或\n\n`yarn global add airs`\n\n# 使用\n\n直接执行`air`启动http server\n\n`air -p 9090`  指定端口\n\n`air -d /tmp/` 指定根目录\n\n所有less文件改为css后缀访问直接现场解析\n\n类似于nginx的ssi(server side include)功能自动启用\n\n\u003e 可以使用连字符将资源合并\n\u003e\n\u003e 连字符的优先级高于配置文件\n\u003e\n\u003e 文件查找解析优先级高于配置文件\n\u003e\n\u003e less文件解析和配置文件优先级高于静态文件\n\n对于js文件\n\n\u003e 同名静态文件的优先级高于配置文件.\n\n对于js,css\n\n优先级: 连字符\u003e配置文件\u003e静态文件\n\n\n\n### 命令\n\n### air serve\n\n开启http server\n\n与直接执行`air`一样\n\n\n\n### air compress\n\n压缩less,javascript\n\n后面可以跟文件列表,将会处理less和js后缀文件\n\n`air compress hello.less hi.less jquery.js etpl.js`\n\n`--debug` 以debug模式压缩\n\n`--clean` 更强的压缩模式,清除console,debugger等\n\n\n\n**break change**\n\nhttps://github.com/less/less.js/releases/tag/v4.0.0\n\nless 4.0 开始, math 默认值发生了改变, 除法必须使用括号了.\n\nhttp://lesscss.org/usage/#less-options-math\n\n可以使用配置文件 `lessOptions` 端, 还原到旧版行为\n\n```json\n{\n\t\"lessOptions\": {\n\t\t\"math\": \"always\"\n\t},\n\t\"static\": {\n\t\t\"js\": {\n\t\t\t\"js/all.js\": [\n\t\t\t\t\"js/jquery.js\",\n\t\t\t\t\"js/etpl.js\"\n\t\t\t]\n\t\t},\n\t\t\"css\": {\n\t\t\t\"css/style.css\": [\n\t\t\t\t\"css/page.less\",\n\t\t\t\t\"css/admin.less\"\n\t\t\t]\n\t\t}\n\t}\n}\n```\n\nlessOptions 指定 math 为 `always`, 行为同3.0版本\n\nlessOptions的配置项有\n\n\u003e math\n\u003e \n\u003e urlArgs , 如果是启动http server方式,query上的参数`urlArgs`,可覆盖此配置文件值\n\u003e\n\u003e globalVars less 的 globalVars 参数, 此配置可由 环境变量 GLOBALVARS (key=value)形式字符串\n\u003e\n\u003e modifyVars less 的 modifyVars 参数, 此配置可由 环境变量 MODIFYVARS (配置key=value) 覆盖, 优先级 -m 参数 (使用http形式是query.modifyVars) \u003e 环境变量 \u003e 配置文件\n\n### air install\n\n安装git hooks, 会将指定目录的git钩子安装到当前仓库, 当前位置必须是仓库根目录\n\n要使用格式化和lint,需要全局安装`prettier`,`eslint`\n\n为启用对vue的支持还需要`eslint-plugin-html`\n\n对`async`支持,还需要添加`babel-eslint`\n\n```\nyarn global add prettier eslint babel-eslint vue-eslint-parser eslint-plugin-vue\n\n```\n\n需 eslint \u003e 5.0.0\n\n要跳过eslint检查,使用\n\n`git commit -n`\n\n或者\n\n`git commit --no-verify`\n\n**参数**\n\n\u003e -dir somedir  可以指定配置文件的目录\n\n\n\n### air lint\n\n手动对指定文件进行格式化和lint\n\n例如:`air lint src/index.js`\n\n\u003e 该命令必须在项目根目录执行,会查找当前目录下的config配置\n\u003e\n\u003e 该命令与commit时执行的命令逻辑相同\n\u003e\n\u003e 可以使用通配符 air lint src/*.js\n\n\n\n**忽略部分lint**\n\n`// eslint-disable-line` 对当前行忽略\n\n`// eslint-disable-next-line` 对下一行忽略\n\n`/* eslint-disable */` 关闭eslint\n\n`/* eslint-enable */`开启eslint\n\n**参数**\n\n\u003e -dir somedir 执行lint和格式化时可以指定配置文件所在目录\n\u003e \n\u003e --lint 默认执行完毕后会使用`git add -u`再次添加此文件,此参数可以阻止该行为\n\n### air template\n\n使用`art-template`模板渲染\n\n`air template tpl.html -o output.html --debug --art`\n\n加上`--debug`为不压缩\n\n`-o`指定输出文件,如果不指定则直接输出到标准输出\n\n`--art` 表示使用`art-template`模板,否则使用ssi\n\n`tpl.html`的数据文件会在`static.json`配置文件中自动查找\n\n\n```json\n\"template\": {\n\t\"tpl.html\": \"data/index.json\"\n}\n```\n\n\n# 使用配置文件\n\n`http server` 和  `air compress` 命令可以使用配置文件\n\n使用配置文件需要有规则的目录结构\n\n在根目录下建立static文件夹\n\n在static目录内建立static.json文件,配置Less和Javascript映射\n\nstatic.json\n\n```\n{\n\t\"static\": {\n\t\t\"js\": {\n\t\t\t\"js/all.js\": [\"js/jquery.js\", \"js/etpl.js\"]\n\t\t},\n\t\t\"css\": {\n\t\t\t\"css/style.css\": [\"css/page.less\", \"css/admin.less\"]\n\t\t}\n\t}\n}\n\n```\n此时,在static目录下执行`air compress` 将会将上述js文件压缩为all.js\n\nless文件解析合并压缩为style.css\n\n`air compress`可在项目中的任意文件夹位置执行\n\n注意\n\n\u003e 被压缩的js需要为es5语法\n\u003e 若要使用ssi,请不要使用中文命名html文件\n\n\n\n### 使用服务端模板渲染\n\n\n\n* 默认已支持nginx ssi 规则,且默认启用\n* 支持另一种模板 `art-template`\n\n如需使用`art-template`模板引擎,使用`air -p 8899 --art`启动\n\n同时,可以使用配置文件对模板填充数据,配置文件声明在`template`段内\n\n```json\n{\n\t\"static\": {\n\t\t\"js\": {\n\t\t\t\"js/all.js\": [\"js/jquery.js\", \"js/etpl.js\"]\n\t\t},\n\t\t\"css\": {\n\t\t\t\"css/style.min.css\": [\"css/page.less\", \"css/admin.less\"]\n\t\t}\n\t},\n\t\"template\": {\n\t\t\"index.html\": \"data/index.json\"\n\t}\n}\n\n```\n\n其中为`index.html`这个请求路径指定了模板数据,数据可使用三种格式\n\n* 直接在配置文件里以对象的方式声明\n* 在配置文件里指定使用一个json文件声明\n* 在配置文件里指定使用一个js文件申明,js文件需为commonJs模块化\n\n\n\n\u003e 模板文件的修改会立即生效\n\u003e\n\u003e 配置文件的修改需重启\n\u003e\n\u003e 模板数据文件的修改需重启\n\u003e\n\u003e query 参数会自动传递给模板,如果有申明同名的模板数据则被覆盖\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuconghou%2Fair","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsuconghou%2Fair","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuconghou%2Fair/lists"}