npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

axil-shared-components-library

v0.1.176

Published

## Getting started

Downloads

292

Readme

Axil Shared Components Library

Getting started

In this directory, first run:

yarn install

Once a yarn lock file is generated, then you can write TypeScript components in the src directory.

Writing components

Each component will be a directory that includes an index.tsx and a styles.module.css.

index.tsx

This is a standard TS component with one exception.

The styles must be imported like import cssClasses from "./styles.module.css".

Then, you can apply styles like className={cssClasses['css-className']}.

Icons

Notice in the src directory, there is a folder called icons.

These are components that directly implement SVG's/images to work-around issues with importing them through Rollup.JS.

For example if you want to add an SVG icon, you would make a new Functional Component file in the icons directory that looks something like this:

export default function SomeIcon() {
  return (
    <svg
      width='24'
      height='24'
      viewBox='0 0 24 24'
    >
      <path id='Path_245' d='M0,0H24V24H0Z' fill='none' />
      <path
        id='Path_246'
        d='M12,8,6,14l1.41,1.41L12,10.83l4.59,4.58L18,14Z'
        fill='#fff'
      />
    </svg>
  );
}

Note: You can edit the styles directly SVG in this file directly by adding the style={{ }} attribute to the svg tag.

Once the SVG component is saved, you can import and use the SVG Component like:

import SomeIcon from "../icons/SomeIcon"

export default function ExampleWithIcon() {
  return (
    <div>
      <h1>Icon Example</h1>
      <SomeIcon />
    </div>;
  )
}

Once you have added your component to the src directory, then make sure you update the index.ts file to export it properly.

export { default as NewComponent } from './new-component';
export * from './new-component';

Bundling Components

Using Rollup.JS (https://rollupjs.org/guide/en/) we are able to bundle files together and publish them to NPM.

In package.json there is the script "build": "rollup -c".

This bundles our src directory into a compiled lib folder.

After running yarn build, we can update the version of the package accordingly.

Publishing Components

First: Make sure you have an NPM account AND are a listed maintainer of the NPM package.

Login in to NPM using npm login.

Run npm publish.

Note: If you didn't update the version in the package it will fail with an authentication error and cancel publishing.

How this works

In this directory, you will notice:

Folders: lib and src,
Package file: package.json,
Rollup config: rollup.config.js,
TS config: tsconfig.json,

Rollup.JS

In order to use Rollup.JS, we need to provide a rollup.config.js file.

import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';

import typescript from 'rollup-plugin-typescript2';
import postCSS from 'rollup-plugin-postcss';

import pkg from './package.json';

export default {
  input: 'src/index.ts',
  output: [
    {
      file: './lib/cjs/index.js',
      format: 'cjs',
    },
    {
      file: './lib/esm/index.js',
      format: 'es',
    },
  ],
  external: [...Object.keys(pkg.peerDependencies || {})],
  plugins: [
    commonjs(),
    typescript({
      typescript: require('typescript'),
    }),
    postCSS({
      plugins: [require('autoprefixer')],
    }),
    nodeResolve(),
  ],
};

This config file takes in our input then we can specify the output to which Rollup outputs our code as a usable JS module.

Notice we are using dependencies nodeResolve, commonjs,typescript, and postcss.

These plugins help process various file types, such as css and typescript, which aren't supported by default.

TypeScript

In order to properly use TypeScript, our tsconfig.json file looks like:

{
  "compilerOptions": {
    "outDir": "lib/esm",
    "module": "esnext",
    "target": "es5",
    "lib": ["es6", "dom", "es2016", "es2017"],
    "jsx": "react-jsx",
    "declaration": true,
    "moduleResolution": "node",
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "esModuleInterop": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "suppressImplicitAnyIndexErrors": true,
    "allowSyntheticDefaultImports": true
  },
  "include": ["src/**/*.ts*"],
  "exclude": ["node_modules", "lib"],
}

Note: In order to use CSS files, we have to make sure our module can interpret the file.

To solve this we add a global.d.ts file to our src directory and in it we have:

declare module '*.module.css' {
  const classes: { readonly [key: string]: string };
  export default classes;
}

This is where we can also define any other types our library may need.