0.0.351 • Published 8 months ago

@carabi/ui v0.0.351

Weekly downloads
-
License
MIT
Repository
-
Last release
8 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.348

9 months ago

0.0.347

9 months ago

0.0.346

9 months ago

0.0.345

10 months ago

0.0.349

9 months ago

0.0.344

10 months ago

0.0.343

10 months ago

0.0.342

10 months ago

0.0.351

8 months ago

0.0.350

8 months ago

0.0.337

11 months ago

0.0.336

11 months ago

0.0.335

11 months ago

0.0.334

11 months ago

0.0.339

11 months ago

0.0.338

11 months ago

0.0.340

11 months ago

0.0.341

11 months ago

0.0.312

11 months ago

0.0.319

11 months ago

0.0.317

11 months ago

0.0.316

11 months ago

0.0.311

12 months ago

0.0.310

12 months ago

0.0.309

12 months ago

0.0.326

11 months ago

0.0.325

11 months ago

0.0.324

11 months ago

0.0.323

11 months ago

0.0.329

11 months ago

0.0.328

11 months ago

0.0.327

11 months ago

0.0.322

11 months ago

0.0.321

11 months ago

0.0.320

11 months ago

0.0.333

11 months ago

0.0.332

11 months ago

0.0.331

11 months ago

0.0.330

11 months ago

0.0.304

12 months ago

0.0.303

12 months ago

0.0.302

12 months ago

0.0.301

12 months ago

0.0.308

12 months ago

0.0.307

12 months ago

0.0.306

12 months ago

0.0.305

12 months ago

0.0.300

12 months ago

0.0.289

1 year ago

0.0.288

1 year ago

0.0.296

12 months ago

0.0.295

12 months ago

0.0.294

12 months ago

0.0.293

12 months ago

0.0.299

12 months ago

0.0.298

12 months ago

0.0.297

12 months ago

0.0.292

12 months ago

0.0.291

1 year ago

0.0.290

1 year ago

0.0.279

1 year ago

0.0.274

1 year ago

0.0.278

1 year ago

0.0.277

1 year ago

0.0.276

1 year ago

0.0.275

1 year ago

0.0.285

1 year ago

0.0.284

1 year ago

0.0.283

1 year ago

0.0.282

1 year ago

0.0.287

1 year ago

0.0.286

1 year ago

0.0.281

1 year ago

0.0.280

1 year ago

0.0.209

1 year ago

0.0.208

1 year ago

0.0.219

1 year ago

0.0.227

1 year ago

0.0.226

1 year ago

0.0.225

1 year ago

0.0.224

1 year ago

0.0.228

1 year ago

0.0.223

1 year ago

0.0.222

1 year ago

0.0.221

1 year ago

0.0.220

1 year ago

0.0.273

1 year ago

0.0.272

1 year ago

0.0.271

1 year ago

0.0.270

1 year ago

0.0.238

1 year ago

0.0.237

1 year ago

0.0.236

1 year ago

0.0.235

1 year ago

0.0.239

1 year ago

0.0.234

1 year ago

0.0.233

1 year ago

0.0.232

1 year ago

0.0.249

1 year ago

0.0.248

1 year ago

0.0.247

1 year ago

0.0.246

1 year ago

0.0.241

1 year ago

0.0.240

1 year ago

0.0.245

1 year ago

0.0.244

1 year ago

0.0.243

1 year ago

0.0.242

1 year ago

0.0.259

1 year ago

0.0.258

1 year ago

0.0.257

1 year ago

0.0.256

1 year ago

0.0.255

1 year ago

0.0.254

1 year ago

0.0.253

1 year ago

0.0.269

1 year ago

0.0.268

1 year ago

0.0.263

1 year ago

0.0.262

1 year ago

0.0.261

1 year ago

0.0.260

1 year ago

0.0.267

1 year ago

0.0.266

1 year ago

0.0.265

1 year ago

0.0.264

1 year ago

0.0.207

1 year ago

0.0.205

1 year ago

0.0.204

1 year ago

0.0.203

1 year ago

0.0.206

1 year ago

0.0.202

1 year ago

0.0.201

1 year ago

0.0.200

1 year ago

0.0.199

1 year ago

0.0.159

1 year ago

0.0.158

1 year ago

0.0.157

1 year ago

0.0.156

1 year ago

0.0.169

1 year ago

0.0.164

1 year ago

0.0.163

1 year ago

0.0.162

1 year ago

0.0.161

1 year ago

0.0.168

1 year ago

0.0.167

1 year ago

0.0.166

1 year ago

0.0.165

1 year ago

0.0.160

1 year ago

0.0.175

1 year ago

0.0.174

1 year ago

0.0.173

1 year ago

0.0.172

1 year ago

0.0.179

1 year ago

0.0.178

1 year ago

0.0.177

1 year ago

0.0.176

1 year ago

0.0.171

1 year ago

0.0.170

1 year ago

0.0.186

1 year ago

0.0.185

1 year ago

0.0.184

1 year ago

0.0.183

1 year ago

0.0.189

1 year ago

0.0.188

1 year ago

0.0.187

1 year ago

0.0.182

1 year ago

0.0.181

1 year ago

0.0.180

1 year ago

0.0.197

1 year ago

0.0.196

1 year ago

0.0.195

1 year ago

0.0.194

1 year ago

0.0.198

1 year ago

0.0.193

1 year ago

0.0.192

1 year ago

0.0.191

1 year ago

0.0.190

1 year ago

0.0.155

1 year ago

0.0.153

1 year ago

0.0.154

1 year ago

0.0.152

1 year ago

0.0.151

1 year ago

0.0.150

1 year ago

0.0.149

1 year ago

0.0.148

1 year ago

0.0.147

1 year ago

0.0.146

1 year ago

0.0.128

1 year ago

0.0.127

1 year ago

0.0.126

1 year ago

0.0.125

1 year ago

0.0.129

1 year ago

0.0.124

1 year ago

0.0.123

1 year ago

0.0.122

1 year ago

0.0.139

1 year ago

0.0.138

1 year ago

0.0.137

1 year ago

0.0.136

1 year ago

0.0.131

1 year ago

0.0.135

1 year ago

0.0.134

1 year ago

0.0.133

1 year ago

0.0.132

1 year ago

0.0.142

1 year ago

0.0.141

1 year ago

0.0.140

1 year ago

0.0.145

1 year ago

0.0.144

1 year ago

0.0.143

1 year ago

0.0.117

1 year ago

0.0.116

1 year ago

0.0.115

1 year ago

0.0.119

1 year ago

0.0.118

1 year ago

0.0.113

1 year ago

0.0.120

1 year ago

0.0.121

1 year ago

0.0.86

1 year ago

0.0.87

1 year ago

0.0.88

1 year ago

0.0.89

1 year ago

0.0.112

1 year ago

0.0.111

1 year ago

0.0.110

1 year ago

0.0.106

1 year ago

0.0.95

1 year ago

0.0.105

1 year ago

0.0.96

1 year ago

0.0.104

1 year ago

0.0.97

1 year ago

0.0.103

1 year ago

0.0.98

1 year ago

0.0.99

1 year ago

0.0.109

1 year ago

0.0.108

1 year ago

0.0.107

1 year ago

0.0.90

1 year ago

0.0.102

1 year ago

0.0.91

1 year ago

0.0.101

1 year ago

0.0.92

1 year ago

0.0.100

1 year ago

0.0.93

1 year ago

0.0.94

1 year ago

0.0.85

1 year ago

0.0.84

1 year ago

0.0.83

1 year ago

0.0.82

1 year ago

0.0.81

1 year ago

0.0.80

1 year ago

0.0.79

1 year ago

0.0.78

1 year ago

0.0.77

1 year ago

0.0.76

1 year ago

0.0.75

1 year ago

0.0.74

1 year ago

0.0.73

1 year ago

0.0.72

1 year ago

0.0.71

1 year ago

0.0.70

1 year ago

0.0.69

1 year ago

0.0.68

1 year ago

0.0.67

1 year ago

0.0.66

1 year ago

0.0.65

1 year ago

0.0.64

1 year ago

0.0.59

1 year ago

0.0.58

1 year ago

0.0.57

1 year ago

0.0.56

1 year ago

0.0.55

1 year ago

0.0.54

1 year ago

0.0.53

1 year ago

0.0.52

1 year ago

0.0.51

1 year ago

0.0.50

1 year ago

0.0.49

1 year ago

0.0.48

1 year ago

0.0.47

1 year ago

0.0.46

1 year ago

0.0.45

1 year ago

0.0.44

1 year ago

0.0.43

1 year ago

0.0.42

1 year ago

0.0.41

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago