{"id":21471291,"url":"https://github.com/liuqing650/maby-lib-cli","last_synced_at":"2026-04-10T01:40:19.326Z","repository":{"id":57290966,"uuid":"119705920","full_name":"Liuqing650/maby-lib-cli","owner":"Liuqing650","description":"构建 library 应用脚手架","archived":false,"fork":false,"pushed_at":"2018-12-05T02:51:08.000Z","size":681,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-27T00:50:22.094Z","etag":null,"topics":["babel","cli","ecmascript2017","ecmascript6","javascript","library","npm","react","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/Liuqing650.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-31T15:32:55.000Z","updated_at":"2018-12-05T02:51:10.000Z","dependencies_parsed_at":"2022-09-01T15:14:39.634Z","dependency_job_id":null,"html_url":"https://github.com/Liuqing650/maby-lib-cli","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Liuqing650%2Fmaby-lib-cli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Liuqing650%2Fmaby-lib-cli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Liuqing650%2Fmaby-lib-cli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Liuqing650%2Fmaby-lib-cli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Liuqing650","download_url":"https://codeload.github.com/Liuqing650/maby-lib-cli/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243988961,"owners_count":20379649,"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":["babel","cli","ecmascript2017","ecmascript6","javascript","library","npm","react","webpack"],"created_at":"2024-11-23T09:33:08.351Z","updated_at":"2025-12-31T00:18:43.289Z","avatar_url":"https://github.com/Liuqing650.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# maby-lib-cli\n\n## 简介\n\n用于快速搭建 library 的基础环境，使用 babel 进行编译， webpack 进行打包。\n\n[![NPM](https://nodei.co/npm/maby-lib-cli.png?downloads=true\u0026downloadRank=true\u0026stars=true)](https://nodei.co/npm/maby-lib-cli/)\n\n## 安装\n\n``` bash\nnpm i maby-lib-cli --save-dev\n\nyarn add maby-lib-cli -D\n```\n\n## 使用\n\n**初始化项目**\n\n\u003e 在安装项目时会默认执行一次初始化项目命令\n\n`\u003e=v1.0.0` 版本只初始化 `package.json` 下的执行命令， 安装完成后需手动执行 `npm run init` 初始化项目\n\n```bash\nmaby-lib init\n```\n\n**开发模式**\n\n```bash\nmaby-lib start\n```\n\n**发布**\n\n```bash\nmaby-lib build\n```\n\n**预览**\n\n```bash\nmaby-lib preview\n```\n\n\u003e 在 `package.json` 中配置好各个启动命令即可\n\n## 更多配置\n\n支持多种方式定义配置文件\n- 在 `package.json` 中可以自定义配置项目\n\n```json\n{\n  \"name\": \"your lib\",\n  ...\n  \"mabycli\": {\n    \"stylelint\": true,\n    \"eslint\": true,\n    \"dir\": \"publish\", // 打包目录 @v2.0.2\n    \"deleteFile\": true, // 只删除 `publish` 路径下的文件 @v2.0.2\n    \"vendors\": [\n      \"react\",\n      \"react-dom\"\n    ]\n  }\n}\n```\n\n- 在 `mabycli.js` 文件下自定义 `mabycli` 中的配置项\n\n\u003e 需在 `package.json` 中指明访问路径\n\n```json\n{\n  \"name\": \"your lib\",\n  ...\n  \"mabycli\": \"./mabycli.js\"\n}\n```\n\n- 在 `mabycli.js` 文件下自定义 `mabycli` 中的配置项\n\n\u003e 需在 `package.json` 中指明访问路径\n\n```json\n{\n  \"name\": \"your lib\",\n  ...\n  \"mabycli\": \"./mabycli.js\"\n}\n```\n\n```js\n  const path = require('path');\n\n  // 使用一个函数时，将给函数传递内置的 plugins、loaders、resolve， 返回类型和 webpack 对应配置一样\n  const getPlugins = (plugins) =\u003e {\n    return plugins.push(new Plugin());\n  }\n  // 一个方法或者一个对象\n  module.exports = () =\u003e ({\n    stylelint: true, // 是否开启 stylelint\n    openBrowser: true, // 是否启动时打开浏览器\n    eslint: true, // 是否开启 eslint\n    vendors: [ // 需要提取的公共库\n      \"react\",\n      \"react-dom\"\n    ],\n    devServerOptions: { // webpack-dev-server 的配置项\n      contentBase: path.join(process.cwd(), 'dist'),\n      overlay: true,\n      headers: {\n        'access-control-allow-origin': '*',\n      },\n      open: true,\n      port: 3300,\n      stats: {\n        modules: false,\n        colors: true\n      }\n    },\n    // v 2.0.0 新增功能\n    plugins: [new Plugin()] || getPlugins, // webpack的 plugins 配置\n    loaders: [{...some loaders}] || getLoaders, // webpack的 loaders 配置\n    resolve: ['.js', '.jsx', '.json'] || getResolve, // webpack的 resolve 配置\n  });\n```\n\n- 在 `.mabycli` 文件下自定义 `mabycli` 中的配置项\n\n```json\n{\n  \"primary-color\": \"#fa8c16\",\n  \"stylelint\": true,\n  \"eslint\": true,\n  \"vendors\": [\n    \"react\",\n    \"react-dom\"\n  ]\n}\n```\n\n- 配置 `antd` 主题样式\n\n**package.json**\n\n```json\n{\n  \"name\": \"your lib\",\n  ...\n  \"dependencies\": {\n    \"antd\": \"^3.11.0\"\n  },\n  \"mabycli\": \"./mabycli.js\",\n  \"theme\": {\n    \"primary-color\": \"#fa541c\" // 设置主题样式\n  }\n}\n```\n\n**.babelrc**\n\n```json\n{\n  \"plugins\": [\n    [\n      \"import\",\n      {\n        \"libraryName\": \"antd\",\n        \"libraryDirectory\": \"es\",\n        \"style\": true\n      }\n    ]\n  ]\n}\n```\n\n**mabycli.js**\n\n```jsx\nconst path = require('path');\nconst fs = require('fs');\nconst ExtractTextPlugin = require('extract-text-webpack-plugin');\n\nconst getTheme = () =\u003e {\n  let theme = {};\n  // 获取主题颜色\n  const pkgPath = path.resolve(__dirname, './package.json');\n  const pkg = fs.existsSync(pkgPath) ? require(pkgPath) : {};\n  if (pkg.theme \u0026\u0026 typeof pkg.theme === 'string') {\n    let cfgPath = pkg.theme;\n    // relative path\n    if (cfgPath.charAt(0) === '.') {\n      cfgPath = path.resolve(__dirname, cfgPath);\n    }\n    const getThemeConfig = require(cfgPath);\n    theme = getThemeConfig();\n  } else if (pkg.theme \u0026\u0026 typeof pkg.theme === 'object') {\n    theme = pkg.theme;\n  }\n  return theme;\n};\n\nconst getLoaders = (loaders) =\u003e {\n  const theme = getTheme();\n  if (!theme) {\n    return loaders;\n  }\n  // 利用 modifyVars 修改主题样式\n  const themeLoaders = {\n    test: /\\.less$/,\n    include: /node_modules/,\n    use: ExtractTextPlugin.extract({\n      fallback: 'style-loader',\n      use: [\n        'css-loader', 'postcss-loader',\n        {\n          loader: 'less-loader',\n          options: {\n            javascriptEnabled: true,\n            modifyVars: theme\n          }\n        }\n      ]\n    })\n  };\n  // 修改内部loader 的 exclude\n  loaders.forEach(loader =\u003e {\n    const isLess = RegExp(loader.test).test('.less');\n    if (isLess) {\n      loader.exclude = /node_modules/;\n    }\n  });\n  loaders.push(themeLoaders);\n  return loaders;\n};\n\n// 修改 ExtractText， 修改antd主题样式时，需要设置 allChunks: true\nconst getExtractTextPlugin = (ExtractText) =\u003e {\n  return {\n    filename: ExtractText.filename,\n    allChunks: true,\n  };\n};\nmodule.exports = () =\u003e ({\n  stylelint: true,\n  port: 10056,\n  loaders: getLoaders,\n  extractTextPlugin: getExtractTextPlugin\n});\n\n```\n\n版本变化信息查看\n\n[发布日志](https://github.com/Liuqing650/maby-lib-cli/blob/master/CHANGELOG.md)\n\n## 目录结构\n\n```text\n  ├─ dist                   压缩文件 library.[version].min.js/library.[version].min.css\n  ├─ example                预览环境\n  |  ├─ example.js          library 测试区\n  |  ├─ index.js            开发模式入口\n  ├─ lib                    生产环境库\n  ├─ src                    开发环境\n  |  ├─ components\n  |  |  ├─ style\n  |  |  ├─ index.js\n  |  ├─ style\n  |  ├─ index.js\n  ├─ .babelrc\n  ├─ .eslintignore\n  ├─ .gitignore\n  ├─ .eslintrc              eslint配置文件夹\n  ├─ postcss.config.js      postcss配置文件夹\n  ├─ README.md\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliuqing650%2Fmaby-lib-cli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fliuqing650%2Fmaby-lib-cli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliuqing650%2Fmaby-lib-cli/lists"}