UNPKG

weapp-tailwindcss

Version:

把 tailwindcss 原子化样式思想,带给小程序开发者们! bring tailwindcss to miniprogram developers!

132 lines (129 loc) 3.92 kB
import { noop } from "./chunk-RR5HCKVQ.mjs"; // src/defaults.ts import { isAllowedClassName, MappingChars2String } from "@weapp-core/escape"; var CSS_FILE_PATTERN = /.+\.(?:wx|ac|jx|tt|q|c|ty)ss$/; var HTML_FILE_PATTERN = /.+\.(?:(?:wx|ax|jx|ks|tt|q|ty|xhs)ml|swan)$/; var JS_FILE_PATTERN = /.+\.[cm]?js?$/; function normalizePath(p) { return p.replace(/\\/g, "/"); } var MPX_STYLES_DIR_PATTERN = /(?:^|\/)styles\/.*\.(?:wx|ac|jx|tt|q|c|ty)ss$/i; var MAIN_CSS_CHUNK_MATCHERS = { "uni-app": (file) => file.startsWith("common/main") || file.startsWith("app"), "uni-app-vite": (file) => file.startsWith("app") || file.startsWith("common/main"), "mpx": (file) => { const normalized = normalizePath(file); if (normalized.startsWith("app")) { return true; } return MPX_STYLES_DIR_PATTERN.test(normalized); }, "taro": (file) => file.startsWith("app"), "remax": (file) => file.startsWith("app"), "rax": (file) => file.startsWith("bundle"), "native": (file) => file.startsWith("app"), "kbone": (file) => /^(?:common\/)?miniprogram-app/.test(file) }; var alwaysFalse = () => false; function createMainCssChunkMatcher() { return (file, appType) => { if (!appType) { return true; } const matcher = MAIN_CSS_CHUNK_MATCHERS[appType]; return matcher ? matcher(file) : true; }; } function getDefaultOptions() { return { /** * wxss 微信小程序 * acss 支付宝小程序 * jxss 京东小程序 * ttss 头条小程序 * qss QQ小程序 * css 最正常的样式文件 * tyss 涂鸦小程序 */ cssMatcher: (file) => CSS_FILE_PATTERN.test(file), /** * wxml 微信小程序 * axml 支付宝小程序 * jxml 京东小程序 * ksml 快手小程序 * ttml 头条小程序 * qml QQ小程序 * tyml 涂鸦小程序 * xhsml 小红书小程序 * swan 百度小程序 */ htmlMatcher: (file) => HTML_FILE_PATTERN.test(file), jsMatcher: (file) => { if (file.includes("node_modules")) { return false; } return JS_FILE_PATTERN.test(file); }, mainCssChunkMatcher: createMainCssChunkMatcher(), wxsMatcher: alwaysFalse, // 参考:https://tailwindcss.com/docs/preflight#border-styles-are-reset-globally cssPreflight: { "box-sizing": "border-box", "border-width": "0", "border-style": "solid", "border-color": "currentColor" }, disabled: false, onLoad: noop, onStart: noop, onEnd: noop, onUpdate: noop, customAttributes: {}, customReplaceDictionary: MappingChars2String, appType: void 0, arbitraryValues: { allowDoubleQuotes: false }, cssChildCombinatorReplaceValue: ["view", "text"], inlineWxs: false, injectAdditionalCssVarScope: false, rewriteCssImports: true, jsPreserveClass: (keyword) => { if (keyword === "*") { return true; } return false; }, disabledDefaultTemplateHandler: false, cssSelectorReplacement: { root: ["page", ".tw-root"], universal: ["view", "text"] }, babelParserOptions: { sourceType: "unambiguous", cache: true, // 预计算好的 cacheKey,避免重复对选项进行 JSON.stringify cacheKey: "st:unambiguous" }, postcssOptions: {}, // 开发版本微信小程序工具和小米13手机上 @property 是有效果的 // 支付宝小程序会直接挂掉 // https://developer.mozilla.org/en-US/docs/Web/CSS/@property cssRemoveProperty: true, cssRemoveHoverPseudoClass: true, ignoreCallExpressionIdentifiers: [], ignoreTaggedTemplateExpressionIdentifiers: ["weappTwIgnore"], replaceRuntimePackages: false, tailwindcssPatcherOptions: { filter(className) { return !isAllowedClassName(className); } }, logLevel: "info" }; } export { getDefaultOptions };