UNPKG

vue-cli-plugin-joinzht-lib

Version:

接入中后台插件

89 lines (84 loc) 4.76 kB
/** * @GeneratorAPI * 允许一个 generator 向 package.json 注入额外的依赖或字段,并向项目中添加文件 */ const slaveMain = require('./portalDoc/main.js') module.exports = (api, options, rootOptions) => { // 注入 public-path.js 文件 api.render('./template', { ...options, }) // 注入开发端口号 api.extendPackage({ scripts: { "start": `vue-cli-service serve --port ${options.port}`, "lint-fix": 'eslint --fix --ext .js --ext .vue src/' } }) api.injectImports(api.entryFile, `import './public-path'`) api.postProcessFiles((files) => { // router 文件里的替换 const routerConfigPath = 'src/router/index.js' if (files[routerConfigPath] && files[routerConfigPath].match(/new(\s)*[a-zA-Z]+/)) { let routerMap = files[routerConfigPath].match(/new(\s)*[a-zA-Z]+(\s)*\(\{[\s\n\r]*[^\}]*[\}\)\,\sa-zA-Z\:]*/)[0] let routerArr = routerMap.split(',') let baseIndex = routerArr.findIndex(item => item.indexOf('base')!==-1) let modeIndex = routerArr.findIndex(item => item.indexOf('mode')!==-1) let newRouter = [...routerArr] if (baseIndex !== -1&& routerArr[baseIndex].indexOf('//') === -1) { if (routerArr[baseIndex].indexOf('({')!==-1) { let newArr = routerArr[baseIndex].split('({') newRouter[baseIndex] = newArr[0] + `({\n` + `base:process.env.VUE_APP_BASE_PATH ||\n(window.__POWERED_BY_QIANKUN__ ? "/${rootOptions.projectName}" : '/')` } else { newRouter[baseIndex] = `\nbase:process.env.VUE_APP_BASE_PATH ||\n(window.__POWERED_BY_QIANKUN__ ? "/${rootOptions.projectName}" : '/')` } } else { newRouter[0] += `,\nbase: process.env.VUE_APP_BASE_PATH ||\n(window.__POWERED_BY_QIANKUN__ ? "/${rootOptions.projectName}" : '/')` } if (modeIndex !== -1&& routerArr[modeIndex].indexOf('//') === -1) { if (routerArr[modeIndex].indexOf('({')!==-1) { let newArr = routerArr[modeIndex].split('({') newRouter[modeIndex] = newArr[0] + `({\n` +`mode: 'history'` } else { newRouter[modeIndex] = `\nmode: 'history'` } } else { newRouter[0] += `,\nmode: 'history'` } const newRouterStr = newRouter.join(',') files[routerConfigPath] = files[routerConfigPath].replace(/new(\s)*[a-zA-Z]+(\s)*\(\{[\s\n\r]*[^\}]*[\}\)\,\sa-zA-Z\:]*/, newRouterStr) } else { console.info('\n暂无法自动转换该项目的 路由 文件,请参考 portal_example/router.js 手动修改\n') } // main.js 文件里的替换 if (!files[api.entryFile].match(/\nnew Vue\(/)) { console.info('\n暂无法自动转换该项目的 main.js 文件,请参考 portal_example/main.js 手动修改\n') } else { files[api.entryFile] = files[api.entryFile].replace( /(new Vue\([\s\S]*)/, slaveMain.replacement ) } }) api.onCreateComplete(() => { api.exitLog('如有不懂,请联系csj。请手动执行 npm run lint-fix 修复eslint') api.exitLog('如有不懂,请联系csj。请手动执行 npm run lint-fix 修复eslint') api.exitLog('如有不懂,请联系csj。请手动执行 npm run lint-fix 修复eslint') api.exitLog('如有不懂,请联系csj。请手动执行 npm run lint-fix 修复eslint') api.exitLog('如有不懂,请联系csj。请手动执行 npm run lint-fix 修复eslint') api.exitLog('如有不懂,请联系csj。请手动执行 npm run lint-fix 修复eslint') api.exitLog('如有不懂,请联系csj。请手动执行 npm run lint-fix 修复eslint') api.exitLog('如有不懂,请联系csj。请手动执行 npm run lint-fix 修复eslint') api.exitLog('如有不懂,请联系csj。请手动执行 npm run lint-fix 修复eslint') api.exitLog('如有不懂,请联系csj。请手动执行 npm run lint-fix 修复eslint') api.exitLog('如有不懂,请联系csj。请手动执行 npm run lint-fix 修复eslint') api.exitLog('如有不懂,请联系csj。请手动执行 npm run lint-fix 修复eslint') api.exitLog('如有不懂,请联系csj。请手动执行 npm run lint-fix 修复eslint') api.exitLog('如有不懂,请联系csj。请手动执行 npm run lint-fix 修复eslint') api.exitLog('如有不懂,请联系csj。请手动执行 npm run lint-fix 修复eslint') api.exitLog('如有不懂,请联系csj。请手动执行 npm run lint-fix 修复eslint') api.exitLog('如有不懂,请联系csj。请手动执行 npm run lint-fix 修复eslint') api.exitLog('如有不懂,请联系csj。请手动执行 npm run lint-fix 修复eslint') api.exitLog('如有不懂,请联系csj。请手动执行 npm run lint-fix 修复eslint') }) }