{"id":15468600,"url":"https://github.com/wendux/keep-loader","last_synced_at":"2025-04-22T11:49:06.192Z","repository":{"id":24159776,"uuid":"123244560","full_name":"wendux/keep-loader","owner":"wendux","description":"一个用于在不同的打包环境下生成不同的代码的Webpack loader，就像C/C++中的宏特性一样。提供了一种在源码中控制打包阶段生成不同代码的能力。","archived":false,"fork":false,"pushed_at":"2023-03-01T16:46:50.000Z","size":407,"stargazers_count":17,"open_issues_count":9,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-04-10T03:15:54.375Z","etag":null,"topics":[],"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/wendux.png","metadata":{"files":{"readme":"readme-en.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":"2018-02-28T07:08:56.000Z","updated_at":"2022-10-07T22:42:25.000Z","dependencies_parsed_at":"2024-10-02T01:41:44.741Z","dependency_job_id":"950728f0-2e49-47dc-9a33-553b1e9a18af","html_url":"https://github.com/wendux/keep-loader","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wendux%2Fkeep-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wendux%2Fkeep-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wendux%2Fkeep-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wendux%2Fkeep-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wendux","download_url":"https://codeload.github.com/wendux/keep-loader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250237793,"owners_count":21397399,"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-10-02T01:41:42.436Z","updated_at":"2025-04-22T11:49:06.168Z","avatar_url":"https://github.com/wendux.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# keep-loader for webpack\n\n## description\n\nGenerate different code based on the development and production environment, just like the macro features of some compiled programming languages, like C.\n\nEnglish document：https://github.com/wendux/keep-loader/blob/master/readme-en.md\n\n中文文档：https://github.com/wendux/keep-loader/blob/master/readme.md\n\n## usage\n\n1. Install keep-loader \n\n   ```javascript\n   npm install keep-loader --save-dev\n   ```\n\n2. Modify your webpack config\n\n   ```javascript\n   module: {\n    ...\n       rules: [\n       ...\n         {\n           test: /\\.js$/,\n           use: [\n             {\n               loader: 'keep-loader',\n               options:{\n                 keep:process.env.NODE_ENV === 'production'?\"prod\":\"dev\"\n               }\n             },\n             {loader: 'babel-loader'}\n           ],\n           include: [resolve('src'), resolve('test')]\n         },\n         ...\n         ]\n       ...  \n    }\n   ```\n\n\nNow, you can use function `KEEP`  in your code , for example:\n\n```javascript\nvar env=\"\"\nKEEP(\"dev\",e=\u003e{\n  console.log(\"I will be keeped in development environment,but removed in other environment\")\n  env=\"development\"\n})\nKEEP(\"prod\",e=\u003e{\n  console.log(\"I will be keeped in production enviroment,but removed in other environment\")\n  env=\"production\"\n})\nconsole.log(env)\n//output \"development\" in development enviroment, \"production\" in prduction environment.\n```\n\n### KEEP(env,callback)\n\n This function defined in keep-loader, you don't have to declare manually .\n\n- env : It must match the value of the keep property defined in keep-loader options  of webpack. and it must be a string literal, not a variable! because the keep-loader is processing source code at building time, rather than at the time of execution.\n- callback: it  will be  called immediately in place.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwendux%2Fkeep-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwendux%2Fkeep-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwendux%2Fkeep-loader/lists"}