0.0.371 • Published 7 months ago

@carabi/ui v0.0.371

Weekly downloads
-
License
MIT
Repository
-
Last release
7 months ago

Used Plugins:

Latest release Downloads Docs

Setup

When running docs:dev for the first time, you may encounter error like vitepress data not properly injected in app in your browser. Restart the server and reload the browser. Please refer to issue #30 for more details.

# install dependencies
npm install

# start the doc app with hot reload, great for testing components
npm run docs:dev

# build the library, available under dist
npm run build

# build the doc app, available under docs/.vitepress/dist
npm run docs:build

# preview the doc app locally from docs/.vitepress/dist
npm run docs:serve

You may use Netlify to auto build and deloy the doc app like this project does.

Develop and test locally

The best way to develop and test your component is by creating demos in docs/components/demo folder, as shown by the example components.

If you want to test the library in your Vue3 app locally:

  • In the root folder of this library, run npm link. This will create a symbolic link to the library.
  • In the root folder of your client app, run npm link my-lib. This will add the symbolic link to the node_modules folder in your client app.
  • You can now import my-lib in your client app.

There is no need to add my-lib to your client app's dependency in this case.

If you made changes to the library, you will need to rebuild the library. Your Vue3 app shall hot reload when the building of library is completed.

How it works

Components

The library is a Vue plugin. The install function in types.ts registers all components under components to Vue globably.

The components are also exported by types.ts so that the client app can import them individually and register them locally, instead of using the library as a plugin. This may be a better option if the client app only use a small set of components in your library.

As there are already many UI component libraries for Vue 3, you may just want to build on top of one of them and create components for your specific needs. The Component B in this starter shows the example of using PrimeVue as the fundation library. However, this means the client app shall also use the same fundation component library as your library does.

The doc app itself is a client app of the libary, therefore PrimeVue is imported in docs/.vitepress/theme/types.ts. The configuration in docs/.vitepress/types.ts below forces VitePress to resolve these modules with no duplication, avoiding error at runtime, as PrimeVue also has Vue in its dependency.

module.exports = {
  vite: {
    resolve: {
      dedupe: ['vue', /primevue\/.+/],
    },
  },
};

In vite._config.ts, format 'umd' is not present in build.lib.formats option. This is because the PrimeVue components used by this library are externalized, and therefore requiring corresponding options in rollupOptions.output.globals. To avoid adding global varaibles for PrimeVue components, 'umd' is removed for simplicity.

Utilities and constants

The library includes example utilities and constants. They are also exported in types.ts. The client app may use them as below:

<script lang="ts">
import { MyConstants, MyUtil } from 'my-lib'

export default {
  data () {
    return {
      magicNum: MyConstants.MAGIC_NUM
    }
  },
  methods: {
    add (a:number, b:number) {
      return MyUtil.add(a, b)
    }
  }
}
</script>

Styling

Individual compopnent may have styles defined in its .vue file. They will be processed, combined and minified into dist/style.css, which is included in the exports list in package.json.

If you have library level styles shared by all components in the library, you may add them to src/assets/main.scss. This file is imported in types.ts, therefore the processed styles are also included into dist/style.css. To avoid conflicting with other global styles, consider pre-fixing the class names or wrapping them into a namespace class.

If you have your own special set of SVG icons, you may create a font file (.woff format) using tools like Icomoon or Fontello. This starter includes an example font file src/assets/fonts/myfont.woff and references it in src/assets/main.scss, with utility icon CSS classes. An icon from the font file is used in Component A. Vite will include the font file into the build, see https://vitejs.dev/guide/assets.html.

The client app shall import style.css, usually in the entry file:

import 'my-lib/dist/style.css';

Third-party dependencies

Third-party libraries used by you library may bloat up the size of your library, if you simply add them to the dependencies in package.json.

The following are some strategies to reduce the size of your library:

Externalization

If you expect the client app of your library may also need the same dependency, you may externalize the dependency. For example, to exclude PrimeVue from your library build artifact, in vite._config.ts, you may have

module.exports = defineConfig({
    rollupOptions: {
      external: ['vue', /primevue\/.+/]
    }
  }
})

The dependency to be externalized may be declared as peer dependency in your library.

Cherry picking

If you don't expect the client app of your library also needing the same dependency, you may embed cherry-picked functions. For example, to embed the fill function of popular library lodash, import the fill function like the following:

import fill from 'lodash/fill';

Even with tree-shaking, the codes being brought into your library may still be large, as the function may have its own dependencies.

Note that import { fill } from 'lodash' or import _ from 'lodash' will not work and will embed the whole lodash library.

Finally, if your client app also use lodash and you don't want lodash to be in both the client app and your libraries, even after cherry-picking, you may consider cherry-picking in component library and re-export them as utils for client to consume, so that the client does not need to depend on lodash, therefore avoiding duplication.

Type generation

In tsconfig.json, the following options instructs tsc to emit declaration (.d.ts files) only, as vite build handles the .js file generation. The generated .d.ts files are sent to dist/types folder.

  "compilerOptions": {
    "declaration": true,
    "emitDeclarationOnly": true,
    "declarationDir": "./dist/types"
  }

In package.json, the line below locates the generated types for library client.

  "types": "./dist/types/types.ts",

In vite._config.ts, build.emptyOutDir is set to false and rimraf is used instead to remove the dist folder before the build. This is to avoid the dist/types folder generated by tsc being deleted when running vite build.

Configuration

TypeScript

In tsconfig.json, compilerOptions.isolatedModules is set to true as recommended by Vite (since esbuild is used). However, enableing this option leads to https://github.com/vitejs/vite/issues/5814. The workaround is to also enable compilerOptions.skipLibCheck.

Dependencies

In package.json, Vue and PrimeVue are declared in both peerDependencies and devDependencies. The former requires the client app to add these dependencies, and the later makes it easier to setup this library by simply running npm install.

0.0.361

7 months ago

0.0.371

7 months ago

0.0.348

1 year ago

0.0.347

1 year ago

0.0.346

1 year ago

0.0.345

1 year ago

0.0.349

1 year ago

0.0.344

1 year ago

0.0.343

1 year ago

0.0.342

1 year ago

0.0.351

1 year ago

0.0.350

1 year ago

0.0.337

1 year ago

0.0.336

1 year ago

0.0.335

1 year ago

0.0.334

1 year ago

0.0.339

1 year ago

0.0.338

1 year ago

0.0.340

1 year ago

0.0.341

1 year ago

0.0.312

2 years ago

0.0.319

1 year ago

0.0.317

1 year ago

0.0.316

1 year ago

0.0.311

2 years ago

0.0.310

2 years ago

0.0.309

2 years ago

0.0.326

1 year ago

0.0.325

1 year ago

0.0.324

1 year ago

0.0.323

1 year ago

0.0.329

1 year ago

0.0.328

1 year ago

0.0.327

1 year ago

0.0.322

1 year ago

0.0.321

1 year ago

0.0.320

1 year ago

0.0.333

1 year ago

0.0.332

1 year ago

0.0.331

1 year ago

0.0.330

1 year ago

0.0.304

2 years ago

0.0.303

2 years ago

0.0.302

2 years ago

0.0.301

2 years ago

0.0.308

2 years ago

0.0.307

2 years ago

0.0.306

2 years ago

0.0.305

2 years ago

0.0.300

2 years ago

0.0.289

2 years ago

0.0.288

2 years ago

0.0.296

2 years ago

0.0.295

2 years ago

0.0.294

2 years ago

0.0.293

2 years ago

0.0.299

2 years ago

0.0.298

2 years ago

0.0.297

2 years ago

0.0.292

2 years ago

0.0.291

2 years ago

0.0.290

2 years ago

0.0.279

2 years ago

0.0.274

2 years ago

0.0.278

2 years ago

0.0.277

2 years ago

0.0.276

2 years ago

0.0.275

2 years ago

0.0.285

2 years ago

0.0.284

2 years ago

0.0.283

2 years ago

0.0.282

2 years ago

0.0.287

2 years ago

0.0.286

2 years ago

0.0.281

2 years ago

0.0.280

2 years ago

0.0.209

2 years ago

0.0.208

2 years ago

0.0.219

2 years ago

0.0.227

2 years ago

0.0.226

2 years ago

0.0.225

2 years ago

0.0.224

2 years ago

0.0.228

2 years ago

0.0.223

2 years ago

0.0.222

2 years ago

0.0.221

2 years ago

0.0.220

2 years ago

0.0.273

2 years ago

0.0.272

2 years ago

0.0.271

2 years ago

0.0.270

2 years ago

0.0.238

2 years ago

0.0.237

2 years ago

0.0.236

2 years ago

0.0.235

2 years ago

0.0.239

2 years ago

0.0.234

2 years ago

0.0.233

2 years ago

0.0.232

2 years ago

0.0.249

2 years ago

0.0.248

2 years ago

0.0.247

2 years ago

0.0.246

2 years ago

0.0.241

2 years ago

0.0.240

2 years ago

0.0.245

2 years ago

0.0.244

2 years ago

0.0.243

2 years ago

0.0.242

2 years ago

0.0.259

2 years ago

0.0.258

2 years ago

0.0.257

2 years ago

0.0.256

2 years ago

0.0.255

2 years ago

0.0.254

2 years ago

0.0.253

2 years ago

0.0.269

2 years ago

0.0.268

2 years ago

0.0.263

2 years ago

0.0.262

2 years ago

0.0.261

2 years ago

0.0.260

2 years ago

0.0.267

2 years ago

0.0.266

2 years ago

0.0.265

2 years ago

0.0.264

2 years ago

0.0.207

2 years ago

0.0.205

2 years ago

0.0.204

2 years ago

0.0.203

2 years ago

0.0.206

2 years ago

0.0.202

2 years ago

0.0.201

2 years ago

0.0.200

2 years ago

0.0.199

2 years ago

0.0.159

2 years ago

0.0.158

2 years ago

0.0.157

2 years ago

0.0.156

2 years ago

0.0.169

2 years ago

0.0.164

2 years ago

0.0.163

2 years ago

0.0.162

2 years ago

0.0.161

2 years ago

0.0.168

2 years ago

0.0.167

2 years ago

0.0.166

2 years ago

0.0.165

2 years ago

0.0.160

2 years ago

0.0.175

2 years ago

0.0.174

2 years ago

0.0.173

2 years ago

0.0.172

2 years ago

0.0.179

2 years ago

0.0.178

2 years ago

0.0.177

2 years ago

0.0.176

2 years ago

0.0.171

2 years ago

0.0.170

2 years ago

0.0.186

2 years ago

0.0.185

2 years ago

0.0.184

2 years ago

0.0.183

2 years ago

0.0.189

2 years ago

0.0.188

2 years ago

0.0.187

2 years ago

0.0.182

2 years ago

0.0.181

2 years ago

0.0.180

2 years ago

0.0.197

2 years ago

0.0.196

2 years ago

0.0.195

2 years ago

0.0.194

2 years ago

0.0.198

2 years ago

0.0.193

2 years ago

0.0.192

2 years ago

0.0.191

2 years ago

0.0.190

2 years ago

0.0.155

2 years ago

0.0.153

2 years ago

0.0.154

2 years ago

0.0.152

2 years ago

0.0.151

2 years ago

0.0.150

2 years ago

0.0.149

2 years ago

0.0.148

2 years ago

0.0.147

2 years ago

0.0.146

2 years ago

0.0.128

2 years ago

0.0.127

2 years ago

0.0.126

2 years ago

0.0.125

2 years ago

0.0.129

2 years ago

0.0.124

2 years ago

0.0.123

2 years ago

0.0.122

2 years ago

0.0.139

2 years ago

0.0.138

2 years ago

0.0.137

2 years ago

0.0.136

2 years ago

0.0.131

2 years ago

0.0.135

2 years ago

0.0.134

2 years ago

0.0.133

2 years ago

0.0.132

2 years ago

0.0.142

2 years ago

0.0.141

2 years ago

0.0.140

2 years ago

0.0.145

2 years ago

0.0.144

2 years ago

0.0.143

2 years ago

0.0.117

2 years ago

0.0.116

2 years ago

0.0.115

2 years ago

0.0.119

2 years ago

0.0.118

2 years ago

0.0.113

2 years ago

0.0.120

2 years ago

0.0.121

2 years ago

0.0.86

2 years ago

0.0.87

2 years ago

0.0.88

2 years ago

0.0.89

2 years ago

0.0.112

2 years ago

0.0.111

2 years ago

0.0.110

2 years ago

0.0.106

2 years ago

0.0.95

2 years ago

0.0.105

2 years ago

0.0.96

2 years ago

0.0.104

2 years ago

0.0.97

2 years ago

0.0.103

2 years ago

0.0.98

2 years ago

0.0.99

2 years ago

0.0.109

2 years ago

0.0.108

2 years ago

0.0.107

2 years ago

0.0.90

2 years ago

0.0.102

2 years ago

0.0.91

2 years ago

0.0.101

2 years ago

0.0.92

2 years ago

0.0.100

2 years ago

0.0.93

2 years ago

0.0.94

2 years ago

0.0.85

2 years ago

0.0.84

2 years ago

0.0.83

2 years ago

0.0.82

2 years ago

0.0.81

2 years ago

0.0.80

2 years ago

0.0.79

2 years ago

0.0.78

2 years ago

0.0.77

2 years ago

0.0.76

2 years ago

0.0.75

2 years ago

0.0.74

2 years ago

0.0.73

2 years ago

0.0.72

2 years ago

0.0.71

2 years ago

0.0.70

2 years ago

0.0.69

2 years ago

0.0.68

2 years ago

0.0.67

2 years ago

0.0.66

2 years ago

0.0.65

2 years ago

0.0.64

2 years ago

0.0.59

2 years ago

0.0.58

2 years ago

0.0.57

2 years ago

0.0.56

2 years ago

0.0.55

2 years ago

0.0.54

2 years ago

0.0.53

2 years ago

0.0.52

2 years ago

0.0.51

2 years ago

0.0.50

2 years ago

0.0.49

2 years ago

0.0.48

2 years ago

0.0.47

2 years ago

0.0.46

2 years ago

0.0.45

2 years ago

0.0.44

2 years ago

0.0.43

2 years ago

0.0.42

2 years ago

0.0.41

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago