1.1.2 • Published 10 months ago

@veldtdevtest/common v1.1.2

Weekly downloads
-
License
-
Repository
-
Last release
10 months ago

Using and Publishing NPM Component Packages

Use as you would a normal component created with create-react-app:

Importing

// container app

import { TestComponent, TestComponent2 } from '@veldtdevtest/common';

Dependencies

All dependencies should be installed in the container React App, since no node modules will be imported.

// container app
npm install
npm i @veldtdevtest/common

CSS Modules

Use of css modules will prevent component css from clashing with container application css. Access css properties like this in the component app:

// component app

import styles from './css/styles.module.css';

...

<div className={styles.myStyle}></div>

Fonts

The Satoshi font will be referenced in the Service and Wellness components, so ensure they are imported in the index.css of the container application.

// container app

@font-face {
  font-family: "Satoshi-Variable";
  src: url("../fonts/Satoshi-Variable.woff2") format("woff2"),
    url("../fonts/Satoshi-Variable.woff") format("woff"),
    url("../fonts/Satoshi-Variable.ttf") format("truetype");
  font-weight: 300 900;
  font-display: swap;
  font-style: normal;
}

Images

Images should be accessed through the /src/images.js file and imported into the component directly, not through a css file.

// component app

import { images } from './images';

...

<img src={images.imageName} />

Publishing to NPM

The script will build the files in /dist.

The only files distributed will be those in /src/components.

Add components as exports to the /src/components/index.js.

If private adjust the package.json

// component app

"private": true

Increment the version number in package.json or reset if you've been testing locally and the version increment is off.

Update types:

patch 0.1.33 > 0.1.34

minor 0.1.33 > 0.2.0

major 0.1.33 > 1.0.0

npm login

npm version <update type>

npm run publish:npm

npm publish

If public:

npm publish --access public

Note: --access=public is needed for scoped packages (@veldt/mypackage) as they're private by default. If it's not scoped and doesn't have the private field set to true in the package.json, it will be public as well.

Check what will be published before publishing

npm publish --dry-run

Choosing a component version

Be sure to remove the ^ from the version number in package.json

// container app

"@veldtdevtest/common": "0.1.33",

Reinstall

// container app

npm install

NPM Component Setup

Files to add

.npmignore

// component app

node_modules/

public/

src/**/*

.index.d.ts

// component app

declare module '@veldtdevtest/common';

/src/components/index.js

// component app

export { default as TestComponent } from './TestComponent';

/src/components/images.js

// component app

import kv from './images/kv.webp';

export const images = { kv }

Dependencies to install

// component app

npm i --save-dev @babel/cli @babel/preset-react

May need this to quiet a warning

// component app

npm i @babel/plugin-proposal-private-property-in-object

package.json script

// component app

"publish:npm": "rm -rf dist && mkdir dist &&  babel src/components -d dist --copy-files"

Other package.json settings

// component app

"name": "@veldtdevtest/common",
"version": "0.1.33",
"private": false,
"main": "dist/index.js",
"files": [
    "dist/**/*"
  ],
"babel": {
  "presets":[
    "@babel/preset-react"
    ]
  },

Notes on "name"

"name": "@veldtdevtest/common",

Creates this folder structure in node_modules:

@veldtdevtest/common/dist/

Maybe use this for the real repo

"name": "@veldt/deservice",

Local Testing in Container

Commit any changes, then in component app:

npm run localtest

This will create a .tgz file on your Desktop.

In the container app update the version to the one on the Desktop:

"dependencies": {
  "@veldtdevtest/common": "file:~/Desktop/veldtdevtest-common-1.1.0.tgz"
}

Install:

npm install
1.1.1

10 months ago

1.1.0

10 months ago

1.0.0

10 months ago

1.1.2

10 months ago

0.1.30

10 months ago

0.1.31

10 months ago

0.1.32

10 months ago

0.1.33

10 months ago

0.1.27

10 months ago

0.1.28

10 months ago

0.1.29

10 months ago

0.1.26

10 months ago

0.1.25

10 months ago

0.1.24

10 months ago

0.1.23

10 months ago

0.1.22

10 months ago

0.1.21

10 months ago

0.1.20

10 months ago

0.1.19

10 months ago

0.1.18

10 months ago

0.1.16

10 months ago

0.1.15

10 months ago

0.1.14

10 months ago

0.1.13

10 months ago

0.1.12

10 months ago

0.1.11

10 months ago

0.1.10

10 months ago

0.1.9

10 months ago

0.1.8

10 months ago

0.1.7

10 months ago

0.1.6

10 months ago

0.1.5

10 months ago

0.1.4

11 months ago

0.1.3

11 months ago

0.1.2

11 months ago

0.1.1

11 months ago