UNPKG

@awcodes/alpine-floating-ui

Version:

Add Floating UI functionality to Alpine 3.x components.

95 lines (83 loc) 2.89 kB
import fs from "fs"; import brotliSize from "brotli-size"; import esbuild from "esbuild"; (() => { if (!fs.existsSync(`./dist`)) { fs.mkdirSync(`./dist`, 0o744); } // Go through each file in the package's "build" directory // and use the appropriate bundling strategy based on its name. fs.readdirSync(`./builds`).forEach((file) => { bundleFile(file); }); })(); function bundleFile(file) { // Based on the filename, give esbuild a specific configuration to build. ({ // This output file is meant to be loaded in a browser's <script> tag. "cdn.js": () => { build({ entryPoints: [`builds/${file}`], outfile: `dist/${file}`, bundle: true, platform: "browser", define: { CDN: true }, }).then(() => { fs.copyFileSync(`dist/${file}`, `astro/public/scripts/${file}`) }); // Build a minified version. build({ entryPoints: [`builds/${file}`], outfile: `dist/${file.replace(".js", ".min.js")}`, bundle: true, minify: true, platform: "browser", define: { CDN: true }, }).then(() => { outputSize("floating-ui", `dist/${file.replace(".js", ".min.js")}`); fs.copyFileSync(`dist/${file.replace(".js", ".min.js")}`, `astro/public/scripts/${file.replace(".js", ".min.js")}`) }); }, "module.js": () => { build({ entryPoints: [`builds/${file}`], outfile: `dist/${file.replace(".js", ".esm.js")}`, bundle: true, platform: "neutral", mainFields: ["main", "module"], }).then(() => { fs.copyFileSync(`dist/${file.replace(".js", ".esm.js")}`, `astro/public/scripts/${file.replace(".js", ".esm.js")}`) }); build({ entryPoints: [`builds/${file}`], outfile: `dist/${file.replace(".js", ".cjs.js")}`, bundle: true, target: ["node10.4"], platform: "node", }).then(() => { fs.copyFileSync(`dist/${file.replace(".js", ".cjs.js")}`, `astro/public/scripts/${file.replace(".js", ".cjs.js")}`) }); }, }[file]()); } function build(options) { options.define || (options.define = {}); options.define["process.env.NODE_ENV"] = process.argv.includes("--production") ? `'production'` : `'development'`; return esbuild .build({ watch: process.argv.includes("--watch"), ...options, }) .catch(() => process.exit(1)); } function outputSize(pkg, file) { let size = bytesToSize(brotliSize.sync(fs.readFileSync(file))); console.log("\x1b[32m", `${pkg}: ${size}`); } function bytesToSize(bytes) { const sizes = ["Bytes", "KB", "MB", "GB", "TB"]; if (bytes === 0) return "n/a"; const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)), 10); if (i === 0) return `${bytes} ${sizes[i]}`; return `${(bytes / 1024 ** i).toFixed(1)} ${sizes[i]}`; }