forked from jd-opensource/nutui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: vite打包配置修改,添加taro标签处理 (jd-opensource#1766)
* feat: 添加range组件、calendar组件在线文档 * fix: 文档调整 * fix: 重构calendar组件 * feat: 日历组件重构,文档修改,功能完善 * fix: 格式化 * fix: 代码格式化调整。 * fix: 去除无用代码 * fix: 文档调整 * fix: 文档调整 * fix: taro demo 样式修改 * feat: range组件功能完善,新增 竖向操作,刻度展示。 * fix: 冲突解决 * feat: taro功能新增,兼容处理,文档修改 * feat: 添加range组件,jdt主题色 * fix: 修改组件初始化逻辑 * feat: 新增h5 日期多选功能 * feat: taro版本添加 日期多选功能 * fix: 修复多选,无法选中开头结尾日期问题 * fix: 文档修改,添加en-US 文档 * fix: 文档完善 * fix: calendar,demo错误修复 * fix: swiper文档修改 * fix: 日历组件问题修复 * fix: calendar taro兼容问题调整 * fix: taro转h5问题修改 * fix: 日历组件修改,vite配置修改,新增plugin * fix: 配置项修改 Co-authored-by: lkjh3214 <[email protected]> Co-authored-by: love_forever <[email protected]>
- Loading branch information
1 parent
2041d07
commit 727c0fe
Showing
4 changed files
with
146 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Components that need to be converted | ||
export const DEFAULT_Components = new Set(['scroll-view', 'picker-view', 'picker-view-column']); | ||
//whether to include the path to the current file | ||
export const judgePath = (paths: string[], targetPath: string) => { | ||
for (let i = 0; i < paths.length; i++) { | ||
let reg = new RegExp(paths[i]); | ||
if (reg.test(targetPath)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
import type { Plugin } from 'vite'; | ||
export interface transformOptions { | ||
exclude?: string[]; | ||
components?: string[]; | ||
envCondition?: string; | ||
include?: string[]; | ||
} | ||
export function transformFinalCode(options: transformOptions = {}): Plugin { | ||
let _options: transformOptions = { | ||
envCondition: 'process.env.TARO_ENV', | ||
components: [], | ||
include: [], | ||
exclude: [] | ||
}; | ||
_options = Object.assign(_options, options); | ||
return { | ||
name: 'transformFinalCode', | ||
enforce: 'post', | ||
async config(config) { | ||
if (!_options.envCondition) { | ||
throw new Error('Environment variable is missing, check the envCondition field'); | ||
} | ||
let _define = {}; | ||
_define[_options.envCondition] = _options.envCondition; | ||
config.define = Object.assign(config.define, _define); | ||
return config; | ||
}, | ||
transform(code: string, id: any) { | ||
let _code = code; | ||
let _components = DEFAULT_Components; | ||
if (_options.components && _options.components.length > 0) { | ||
_components = new Set(_options.components); | ||
} | ||
if (_options.exclude && _options.exclude.length !== 0 && judgePath(_options.exclude, id)) { | ||
return _code; | ||
} | ||
if (_options.include && _options.include.length !== 0 && !judgePath(_options.include, id)) { | ||
return _code; | ||
} | ||
_components.forEach((tagName) => { | ||
let Reg = new RegExp(`"${tagName}"`, 'ig'); | ||
const r = `function(){if(${_options.envCondition} === 'h5'){return 'taro-${tagName}'}else{return '${tagName}'}}()`; | ||
_code = _code.replace(Reg, r); | ||
}); | ||
return _code; | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters