From e92b4a9312d2282e485db0a7c916718cd426e018 Mon Sep 17 00:00:00 2001 From: winston Date: Mon, 13 Jun 2022 08:48:36 +0200 Subject: [PATCH] feat: npm package: hybrid cjs+esm support (#14) * feat(npm): add build script for hybrid cjs+esm support * style: fix mixed indents * allow import from CSS * doc: instructions on how to import css file * refactor(npm): use esbuild.js for a single build command * chore: fix mixed indents * fix(npm): rename file extension in npm include list Co-authored-by: sakkke Co-authored-by: Pocco81 <58336662+Pocco81@users.noreply.github.com> Co-authored-by: Pocco81 --- .gitignore | 1 + esbuild.js | 15 +++++++++++++++ package.json | 21 ++++++++++++++------- 3 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 esbuild.js diff --git a/.gitignore b/.gitignore index c2658d7..1eae0cf 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +dist/ node_modules/ diff --git a/esbuild.js b/esbuild.js new file mode 100644 index 0000000..7d14d1e --- /dev/null +++ b/esbuild.js @@ -0,0 +1,15 @@ +const esbuild = require('esbuild'); + +const buildCJS = esbuild.build({ + entryPoints: ['./index.js'], + outfile: './dist/index.cjs', + format: 'cjs' +}) + +const buildESM = esbuild.build({ + entryPoints: ['./index.js'], + outfile: './dist/index.mjs', + format: 'esm' +}) + +Promise.all([buildCJS, buildESM]).catch(() => process.exit(1)) diff --git a/package.json b/package.json index 5329038..fce1854 100644 --- a/package.json +++ b/package.json @@ -1,19 +1,25 @@ { "name": "@catppuccin/palette", - "version": "0.1.4", + "version": "0.1.5", "description": "Soothing pastel themes for the high-spirited!", - "main": "index.js", - "type": "module", + "main": "dist/index.js", + "module": "dist/index.mjs", "exports": { - ".": "./index.js", + ".": { + "require": "./dist/index.cjs", + "import": "./dist/index.mjs" + }, "./style": "./css/catppuccin.css" }, "scripts": { - "test": "ava" + "test": "ava", + "build": "node esbuild.js", + "prepublishOnly": "npm run build" }, "files": [ "css/", - "index.js", + "dist/index.cjs", + "dist/index.mjs", "index.d.ts" ], "types": "index.d.ts", @@ -39,6 +45,7 @@ }, "homepage": "https://github.com/catppuccin/palette#readme", "devDependencies": { - "ava": "^4.2.0" + "ava": "^4.2.0", + "esbuild": "^0.14.42" } }