Skip to content
Myr

index.js

This file

Path

bin/index.js

71 lines · 1.8 KiB · JavaScript

Last changed by

feat: add `clsx/lite` moduleLuke Edwardsbefore adoption1a49142

History of this file

Take it

chore: build CJS & UMD files manually;Luke Edwardsbefore adoption3712966

lines 1–17why, one step back
1// @ts-check
2const fs = require('fs');3const zlib = require('zlib');4const { minify } = require('terser');5const pkg = require('../package.json');67/**8 * @param {string} file9 * @param {string} source10 */11function write(file, source) {12 let isModule = !source.startsWith('!function');13 let result = minify(source, {14 module: isModule,15 compress: true,16 });17

feat: add `clsx/lite` moduleLuke Edwardsbefore adoption1a49142

lines 18–24why, one step back
18 if (result.code) {
19 fs.writeFileSync(file, result.code);20 let size = zlib.gzipSync(result.code).byteLength;21 console.log('~> "%s" (%d b)', file, size);22 } else {23 console.error('!! "%s" ::', file, result.error);24 }

chore: build CJS & UMD files manually;Luke Edwardsbefore adoption3712966

lines 25–26why, one step back
25}
26

feat: add `clsx/lite` moduleLuke Edwardsbefore adoption1a49142

lines 27–31why, one step back
27/**
28 * @typedef Export29 * @property {Condition} import30 * @property {Condition} default31 */

chore: build CJS & UMD files manually;Luke Edwardsbefore adoption3712966

line 32why, one step back
32

feat: add `clsx/lite` moduleLuke Edwardsbefore adoption1a49142

lines 33–37why, one step back
33/**
34 * @typedef Condition35 * @property {string} types36 * @property {string} default37 */

chore: build CJS & UMD files manually;Luke Edwardsbefore adoption3712966

line 38why, one step back
38

feat: add `clsx/lite` moduleLuke Edwardsbefore adoption1a49142

lines 39–44why, one step back
39/**
40 * @param {string} file41 * @param {"." | "./lite"} entry42 */43function bundle(file, entry) {44 fs.existsSync('dist') || fs.mkdirSync('dist');

chore: build CJS & UMD files manually;Luke Edwardsbefore adoption3712966

line 45why, one step back
45

feat: add `clsx/lite` moduleLuke Edwardsbefore adoption1a49142

lines 46–71why, one step back
46 /**
47 * @type {Export}48 */49 let output = pkg.exports[entry];50 let input = fs.readFileSync(file, 'utf8');5152 // copy for ESM file53 write(output.import.default, input);5455 // transform ESM -> CJS exports56 write(output.default.default, input.replace('export function', 'function').replace(57 'export default clsx;',58 'module.exports = clsx;\n'59 + 'module.exports.clsx = clsx;'60 ));6162 if (entry === '.') {63 // transform ESM -> UMD exports64 input = input.replace('export function', 'function').replace('export default clsx;', 'return clsx.clsx=clsx, clsx;');65 write(pkg.unpkg, '!function(global,factory){"object"==typeof exports&&"undefined"!=typeof module?module.exports=factory():"function"==typeof define&&define.amd?define(factory):global.clsx=factory()}(this,function(){' + input + '});');66 }67}6869bundle('src/index.js', '.');70console.log('---');71bundle('src/lite.js', './lite');