UNPKG

weapp-tailwindcss

Version:

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

172 lines (160 loc) 5.34 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _chunkLSSLYD6Bjs = require('./chunk-LSSLYD6B.js'); var _chunkOGROHM4Ljs = require('./chunk-OGROHM4L.js'); var _chunkYOYWDNJIjs = require('./chunk-YOYWDNJI.js'); var _chunkO335YLYHjs = require('./chunk-O335YLYH.js'); // src/bundlers/vite/index.ts var debug = _chunkLSSLYD6Bjs.createDebug.call(void 0, ); function UnifiedViteWeappTailwindcssPlugin(options = {}) { const opts = _chunkYOYWDNJIjs.getCompilerContext.call(void 0, options); const { disabled, onEnd, onLoad, onStart, onUpdate, templateHandler, styleHandler, jsHandler, mainCssChunkMatcher, appType, setMangleRuntimeSet, cache, twPatcher } = opts; if (disabled) { return; } twPatcher.patch(); onLoad(); return { name: _chunkOGROHM4Ljs.vitePluginName, enforce: "post", async generateBundle(_opt, bundle) { debug("start"); onStart(); const entries = Object.entries(bundle); const groupedEntries = _chunkO335YLYHjs.getGroupedEntries.call(void 0, entries, opts); const runtimeSet = await twPatcher.getClassSet(); setMangleRuntimeSet(runtimeSet); debug("get runtimeSet, class count: %d", runtimeSet.size); const promises = []; if (Array.isArray(groupedEntries.html)) { for (const element of groupedEntries.html) { const [file, originalSource] = element; const oldVal = originalSource.source.toString(); const hash = cache.computeHash(oldVal); cache.calcHashValueChanged(file, hash); promises.push( cache.process( file, () => { const source = cache.get(file); if (source) { originalSource.source = source; debug("html cache hit: %s", file); } else { return false; } }, async () => { originalSource.source = await templateHandler(oldVal, { runtimeSet }); onUpdate(file, oldVal, originalSource.source); debug("html handle: %s", file); return { key: file, source: originalSource.source }; } ) ); } } if (Array.isArray(groupedEntries.js)) { for (const element of groupedEntries.js.filter((x) => x[1].type === "chunk")) { const [file, originalSource] = element; const rawSource = originalSource.code; const hash = cache.computeHash(rawSource); cache.calcHashValueChanged(file, hash); promises.push( cache.process( file, () => { const source = cache.get(file); if (source) { originalSource.code = source; debug("js cache hit: %s", file); } else { return false; } }, async () => { const mapFilename = `${file}.map`; const hasSourceMap = Boolean(bundle[mapFilename]); const { code, map } = await jsHandler(rawSource, runtimeSet, { generateMap: hasSourceMap }); originalSource.code = code; onUpdate(file, rawSource, code); debug("js handle: %s", file); if (hasSourceMap && map) { ; bundle[mapFilename].source = map.toString(); } return { key: file, source: code }; } ) ); } } if (Array.isArray(groupedEntries.css)) { for (const element of groupedEntries.css) { const [file, originalSource] = element; const rawSource = originalSource.source.toString(); const hash = cache.computeHash(rawSource); cache.calcHashValueChanged(file, hash); promises.push( cache.process( file, () => { const source = cache.get(file); if (source) { originalSource.source = source; debug("css cache hit: %s", file); } else { return false; } }, async () => { const { css } = await styleHandler(rawSource, { isMainChunk: mainCssChunkMatcher(originalSource.fileName, appType), postcssOptions: { options: { from: file } } }); originalSource.source = css; onUpdate(file, rawSource, css); debug("css handle: %s", file); return { key: file, source: css }; } ) ); } } await Promise.all(promises); onEnd(); debug("end"); } }; } exports.UnifiedViteWeappTailwindcssPlugin = UnifiedViteWeappTailwindcssPlugin;