UNPKG

weapp-tailwindcss-webpack-plugin

Version:

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

145 lines (142 loc) 4.25 kB
import { createDebug } from "./chunk-3AUX4FGE.mjs"; import { getCompilerContext } from "./chunk-XRPBGBW5.mjs"; // src/bundlers/gulp/index.ts import { Buffer } from "node:buffer"; import stream from "node:stream"; var debug = createDebug(); var Transform = stream.Transform; function createPlugins(options = {}) { const opts = getCompilerContext(options); const { templateHandler, styleHandler, jsHandler, setMangleRuntimeSet, cache, twPatcher } = opts; let runtimeSet = /* @__PURE__ */ new Set(); twPatcher.patch(); function transformWxss(options2 = {}) { return new Transform({ objectMode: true, async transform(file, _encoding, callback) { runtimeSet = await twPatcher.getClassSet(); setMangleRuntimeSet(runtimeSet); const error = null; if (file.contents) { const rawSource = file.contents.toString(); const hash = cache.computeHash(rawSource); cache.calcHashValueChanged(file.path, hash); await cache.process( file.path, () => { const source = cache.get(file.path); if (source) { file.contents = Buffer.from(source); debug("css cache hit: %s", file.path); } else { return false; } }, async () => { const { css } = await styleHandler(rawSource, { isMainChunk: true, ...options2 }); file.contents = Buffer.from(css); debug("css handle: %s", file.path); return { key: file.path, source: css }; } ); } callback(error, file); } // construct(callback) { // debug('transformWxss start') // callback() // } }); } function transformJs(options2 = {}) { return new Transform({ objectMode: true, async transform(file, _encoding, callback) { const error = null; if (file.contents) { const rawSource = file.contents.toString(); const hash = cache.computeHash(rawSource); cache.calcHashValueChanged(file.path, hash); await cache.process( file.path, () => { const source = cache.get(file.path); if (source) { file.contents = Buffer.from(source); debug("js cache hit: %s", file.path); } else { return false; } }, async () => { const { code } = await jsHandler(rawSource, runtimeSet, options2); file.contents = Buffer.from(code); debug("js handle: %s", file.path); return { key: file.path, source: code }; } ); } callback(error, file); } }); } function transformWxml(options2 = {}) { return new Transform({ objectMode: true, async transform(file, _encoding, callback) { const error = null; if (file.contents) { const rawSource = file.contents.toString(); const hash = cache.computeHash(rawSource); cache.calcHashValueChanged(file.path, hash); await cache.process( file.path, () => { const source = cache.get(file.path); if (source) { file.contents = Buffer.from(source); debug("html cache hit: %s", file.path); } else { return false; } }, async () => { const code = await templateHandler(rawSource, { runtimeSet, ...options2 }); file.contents = Buffer.from(code); debug("html handle: %s", file.path); return { key: file.path, source: code }; } ); } callback(error, file); } }); } return { transformWxss, transformWxml, transformJs }; } export { createPlugins };