I've published the library but there's a problem. I need to do something like this to access my code:
const {
default: { getContrast },
} = require('@akashshyam/color-utilities/lib/index');
console.log(getContrast('#ffffff'));
There are two problems:
- I need to use the
lib
folder where it should be just@akashshyam/color-utilities/index
- I've exported a default object. But to access that I need to use the
default
property
Here's the package.json
{
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"build": "tsc",
"test": "mocha --reporter spec --require ts-node/register src/**/*.test.ts",
"prepare": "npm run build",
"lint": "eslint",
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
"prepublishOnly": "npm run test && npm run lint",
"preversion": "npm run lint",
"version": "npm run format && git add .",
"postversion": "git push && git push --tags"
},
"files": [
"/lib"
],
}
Now, the folder structure before and after compiling to vanilla JS:
All of the files except index.js
have one or more functions which are exported. I'm creating an object in index.js
which contains all the functions:
import { getContrast } from './colorContrast';
import { HSLToHex, HSLToRGB, RGBToHSL, RGBToHex, hexToHSL, hexToRGB } from './colorConversion';
import { separateHSL, separateRGB } from './colorSeparation';
import { validateHSL, validateHex, validateRGB } from './colorValidators';
export default {
getContrast,
HSLToHex,
HSLToRGB,
RGBToHSL,
RGBToHex,
hexToHSL,
hexToRGB,
separateHSL,
separateRGB,
validateHSL,
validateHex,
validateRGB,
};
Also, I'd like to combine these multiple files into one file and minify the code. I'm currently using the typescript compiler for compiling these files. I tried webpack but I had some errors. I'm open to using bundlers but please provide the configuration. I hope you guys can shed some light on any of these points. Thanks in advance!