weapp-tailwindcss
Version:
把 tailwindcss 原子化样式思想,带给小程序开发者们! bring tailwindcss to miniprogram developers!
145 lines (137 loc) • 4.59 kB
JavaScript
Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _chunkLSSLYD6Bjs = require('./chunk-LSSLYD6B.js');
var _chunkYOYWDNJIjs = require('./chunk-YOYWDNJI.js');
// src/bundlers/gulp/index.ts
var _buffer = require('buffer');
var _stream = require('stream'); var _stream2 = _interopRequireDefault(_stream);
var debug = _chunkLSSLYD6Bjs.createDebug.call(void 0, );
var Transform = _stream2.default.Transform;
function createPlugins(options = {}) {
const opts = _chunkYOYWDNJIjs.getCompilerContext.call(void 0, 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.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.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.Buffer.from(source);
debug("js cache hit: %s", file.path);
} else {
return false;
}
},
async () => {
const { code } = await jsHandler(rawSource, runtimeSet, options2);
file.contents = _buffer.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.Buffer.from(source);
debug("html cache hit: %s", file.path);
} else {
return false;
}
},
async () => {
const code = await templateHandler(rawSource, {
runtimeSet,
...options2
});
file.contents = _buffer.Buffer.from(code);
debug("html handle: %s", file.path);
return {
key: file.path,
source: code
};
}
);
}
callback(error, file);
}
});
}
return {
transformWxss,
transformWxml,
transformJs
};
}
exports.createPlugins = createPlugins;
;