﻿# Quick start {#quick-start}

Choose full installation, manual on-demand imports, or automatic on-demand imports. Install the runtime dependencies in your Vue 3 application:

```sh
npm install vue element-plus @94ai-plus/common-ui @94ai-plus/nf-theme-chalk
```

## Full installation {#full-import}

Register Element Plus and CommonUI in `main.ts` and load their complete styles. `App.vue` is your application root component.

```ts
import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import CommonUI, { enUs } from '@94ai-plus/common-ui'
import App from './App.vue'
import 'element-plus/dist/index.css'
import '@94ai-plus/nf-theme-chalk/index.css'

const app = createApp(App)
app.use(ElementPlus)
app.use(CommonUI, { theme: 'chalk', locale: enUs })
app.mount('#app')
```

## Manual on-demand CJS imports {#manual-cjs}

The on-demand examples below use `nf-button`. For standalone integration, install the packages for the components you use:

```sh
npm install vue element-plus @94ai-plus/nf-button @94ai-plus/nf-theme-chalk
```

In a build environment that supports CommonJS, Vue single-file components and CSS loading, import and register individual component packages and load only the CommonUI styles you need. Entry file `main.cjs`:

```js
const { createApp } = require('vue')
const ElementPlus = require('element-plus').default
const NfButton = require('@94ai-plus/nf-button').default
const App = require('./App.vue').default
require('element-plus/dist/index.css')
require('@94ai-plus/nf-theme-chalk/nf-button.css')

const app = createApp(App)
app.use(ElementPlus)
app.use(NfButton)
app.mount('#app')
```

`require()` uses the public CommonJS package entry, with no internal `dist` or legacy `lib` paths. Access the default component export through `.default`. A bundler must process `.vue` and CSS; this is not a standalone Node.js script. CJS does not offer the same static Tree Shaking conditions as ESM, so use individual packages for on-demand imports.

### Webpack 5 configuration (CJS) {#cjs-webpack-config}

For a Vue 3 project with JavaScript SFCs, save the entry above as `src/main.cjs` and the button template in the next section as `src/App.vue`. Install these build dependencies:

```sh
npm install -D webpack@5 webpack-cli@6 vue-loader@17 @vue/compiler-sfc@3.5.44 style-loader css-loader html-webpack-plugin
```

Create `webpack.config.cjs` in the project root. The `.cjs` extension also works when `package.json` declares `"type": "module"`:

```js
const path = require('node:path')
const webpack = require('webpack')
const { VueLoaderPlugin } = require('vue-loader')
const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
  mode: 'production',
  entry: './src/main.cjs',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'app.js',
    clean: true,
  },
  resolve: {
    extensions: ['.js', '.cjs', '.mjs', '.vue'],
    alias: {
      'vue$': require.resolve('vue/dist/vue.runtime.esm-bundler.js'),
    },
    byDependency: {
      commonjs: { conditionNames: ['require', 'default'] },
    },
  },
  module: {
    rules: [
      { test: /\.vue$/, loader: 'vue-loader' },
      { test: /\.css$/, use: ['style-loader', 'css-loader'] },
    ],
  },
  plugins: [
    new VueLoaderPlugin(),
    new HtmlWebpackPlugin({ template: './public/index.html' }),
    new webpack.DefinePlugin({
      __VUE_OPTIONS_API__: JSON.stringify(true),
      __VUE_PROD_DEVTOOLS__: JSON.stringify(false),
      __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: JSON.stringify(false),
    }),
  ],
}
```

`vue-loader` and `VueLoaderPlugin` compile `.vue` files. `css-loader` and `style-loader` process and inject CSS. `HtmlWebpackPlugin` injects the bundle into the HTML template below. This example uses JavaScript SFCs; TypeScript SFCs also need an appropriate TypeScript loader.

`resolve.byDependency.commonjs.conditionNames` explicitly selects the `require` condition so `@94ai-plus/nf-button` resolves to its public CJS entry instead of the higher-priority default `browser` entry. The exact Vue alias keeps the entry, SFCs and dependencies on one runtime; `vue-loader` precompiles templates.

Create `public/index.html` with the mount element:

```html
<!doctype html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CommonUI Webpack CJS</title>
</head>
<body>
  <div id="app"></div>
</body>
</html>
```

Run this command from the application root. Serve the generated `dist/index.html` over HTTP. In an existing Webpack project, merge the settings while keeping its plugins and application rules.

```sh
npm exec webpack -- --config webpack.config.cjs
```

## Ready-to-use manual ES Module imports {#manual-esm}

Use native `import` with individual component packages, register the required components, and load their theme styles. Entry file `main.ts`:

```ts
import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import NfButton from '@94ai-plus/nf-button'
import App from './App.vue'
import 'element-plus/dist/index.css'
import '@94ai-plus/nf-theme-chalk/nf-button.css'

const app = createApp(App)
app.use(ElementPlus)
app.use(NfButton)
app.mount('#app')
```

Alternatively, replace the component import above with a named import from the full package:

```ts
import { NfButton } from '@94ai-plus/common-ui'
```

ES Modules let bundlers perform Tree Shaking in production; the actual result depends on your build configuration. Import styles explicitly, and omit `app.use(CommonUI)` when using on-demand imports. Both manual approaches can use this `App.vue`:

```vue
<template>
  <NfButton type="primary">Button</NfButton>
</template>
```

## Automatic on-demand imports {#auto-import}

Use `unplugin-vue-components` with `@94ai-plus/common-ui-resolver` to import components and theme styles based on template tags. Install the build dependencies:

```sh
npm install -D unplugin-vue-components @94ai-plus/common-ui-resolver
```

### Vite / Webpack configuration {#vite-config}

<span id="webpack-config"></span>

Merge the following plugin configuration into your `Vite` or `Webpack` config file. For Webpack, keep the existing Vue SFC, TypeScript and CSS loader configuration.

::: code-group

```ts [vite.config.ts]
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { CommonUIResolver } from '@94ai-plus/common-ui-resolver'

export default defineConfig({
  plugins: [
    vue(),
    Components({
      dts: 'components.d.ts',
      resolvers: [CommonUIResolver({ theme: 'chalk' }), ElementPlusResolver()],
    }),
  ],
})
```

```js [webpack.config.mjs]
import Components from 'unplugin-vue-components/webpack'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { CommonUIResolver } from '@94ai-plus/common-ui-resolver'

export default {
  plugins: [
    Components({
      dts: 'components.d.ts',
      resolvers: [CommonUIResolver({ theme: 'chalk' }), ElementPlusResolver()],
    }),
  ],
}
```


The entry file only needs to mount the app. Full CommonUI or Element Plus registration is unnecessary; the resolvers generate imports for the `Nf*` and `El*` components used in templates:

```ts
import { createApp } from 'vue'
import App from './App.vue'

createApp(App).mount('#app')
```

```vue
<template>
  <NfButton type="primary">Button</NfButton>
  <ElButton>Element Plus button</ElButton>
</template>
```

Resolvers do not install dependencies. Install the corresponding component and theme packages. Include `components.d.ts` in your project’s `tsconfig.json` for template types. Automatic component imports target template tags; services such as `Message`, `Notification` and `Confirm` still require explicit script imports.

`CommonUIResolver()` defaults to Chalk. Set `theme: false` to disable automatic style imports, or use `exclude` to skip matching components. For OEM, set `theme: 'oem'`, install `@94ai-plus/nf-theme-oem`, and set `theme="oem"` on `NfConfigProvider`.

## UMD {#umd}

No build tools are needed. Save a complete example below as an HTML file and serve it over local HTTP. CDN URLs use fixed example versions; update CommonUI and theme package versions together when upgrading.

### Using component UMD builds directly in HTML {#html-umd}

#### Example 1: Full installation {#html-umd-full}

Load Vue, Element Plus and CommonUI UMD scripts in that order, then create the app. The full package exposes `window.CommonUi`; register its `.default` export. Load theme CSS after Element Plus CSS.

```html
<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CommonUI UMD</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/element-plus@2.14.7/dist/index.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@94ai-plus/nf-theme-chalk@1.0.0-alpha.4/dist/css/index.css">
</head>
<body>
  <div id="app">
    <p>Click count: {{ count }}</p>
    <nf-button type="primary" @click="count += 1">Click +1</nf-button>
    <el-button @click="count = 0">Reset</el-button>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/vue@3.5.44/dist/vue.global.prod.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/element-plus@2.14.7/dist/index.full.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/@94ai-plus/common-ui@1.0.0-alpha.4/dist/browser/index.umd.js"></script>
  <script>
    const app = Vue.createApp({
      setup() {
        const count = Vue.ref(0)
        return { count }
      },
    })
    app.use(ElementPlus)
    app.use(CommonUi.default, { theme: 'chalk' })
    app.mount('#app')
  </script>
</body>
</html>
```

#### Example 2: Individual components {#html-umd-component}

For individual components, load their UMD packages and component styles. This example only uses `NfButton`, whose UMD depends only on `Vue`. Load Element Plus first for components that depend on it.

```html
<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CommonUI UMD component</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@94ai-plus/nf-theme-chalk@1.0.0-alpha.4/dist/css/nf-button.css">
</head>
<body>
  <div id="app">
    <p>Click count: {{ count }}</p>
    <nf-button type="primary" @click="count += 1">Click +1</nf-button>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/vue@3.5.44/dist/vue.global.prod.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/@94ai-plus/nf-button@1.0.0-alpha.4/dist/browser/index.umd.js"></script>
  <script>
    const app = Vue.createApp({
      setup() {
        const count = Vue.ref(0)
        return { count }
      },
    })
    app.use(NfButton.default)
    app.mount('#app')
  </script>
</body>
</html>
```

Use kebab-case component and attribute names in HTML, such as `<nf-button>` and `<nf-radio-group :popper-options="options">`. Always include explicit closing tags; SFC self-closing syntax does not work here. These scripts load synchronously in order; do not add `async` and break dependency ordering.

### Using importmap in HTML {#html-importmap}

Use native browser ES Modules and importmap without bundling. Unlike the UMD examples, this loads `dist/browser/index.js` with `import` and does not depend on `window.CommonUi`. Element Plus also uses its browser ESM build, and all modules share the same mapped Vue instance.

```html
<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CommonUI importmap</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/element-plus@2.14.7/dist/index.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@94ai-plus/nf-theme-chalk@1.0.0-alpha.4/dist/css/index.css">
</head>
<body>
  <div id="app">
    <p>Click count: {{ count }}</p>
    <nf-button type="primary" @click="count += 1">Click +1</nf-button>
    <el-button @click="count = 0">Reset</el-button>
  </div>
  <script type="importmap">
  {
    "imports": {
      "vue": "https://cdn.jsdelivr.net/npm/vue@3.5.44/dist/vue.esm-browser.prod.js",
      "element-plus": "https://cdn.jsdelivr.net/npm/element-plus@2.14.7/dist/index.full.mjs",
      "@94ai-plus/common-ui": "https://cdn.jsdelivr.net/npm/@94ai-plus/common-ui@1.0.0-alpha.4/dist/browser/index.js"
    }
  }
  </script>
  <script type="module">
    import { createApp, ref } from 'vue'
    import ElementPlus from 'element-plus'
    import CommonUI from '@94ai-plus/common-ui'

    const app = createApp({
      setup() {
        const count = ref(0)
        return { count }
      },
    })
    app.use(ElementPlus)
    app.use(CommonUI, { theme: 'chalk' })
    app.mount('#app')
  </script>
</body>
</html>
```

Place the importmap before the first module script and use valid JSON. Open the page over HTTP(S) in a modern browser that supports importmap. For browsers without native importmap support, load `es-module-shims` before the importmap. This polyfill does not add support for old browsers unsupported by Vue 3 or Element Plus.

For native browser modules, use `dist/browser/index.js`, not the bundler-oriented `dist/es/index.mjs`, which still contains bare imports of same-scope packages. You can also map `"@94ai-plus/nf-button": "https://cdn.jsdelivr.net/npm/@94ai-plus/nf-button@1.0.0-alpha.4/dist/browser/index.js"`, then `import NfButton from '@94ai-plus/nf-button'` and call `app.use(NfButton)`, using the component CSS instead. Avoid mixing global and ESM Vue builds on the same page, which creates multiple Vue instances.

## Internationalization {#locale}

Built-in languages include Chinese, English, Japanese (ja), Spanish (es), Indonesian (id), Thai (th), Tagalog (tl) and Portuguese (pt). With full installation, replace the earlier `app.use(CommonUI, …)` with a shared locale context for dynamic switching:

```ts
import { createLocale, enUs } from '@94ai-plus/common-locale'

const locale = createLocale(enUs)
app.use(CommonUI, { theme: 'chalk', locale })
locale.setLocale('ja')
```

Built-in locales select the matching Element Plus locale; an explicit `elementPlusLocale` takes precedence. Custom slot content is not translated automatically. With on-demand imports, configure language and theme using [NfConfigProvider](https://front.94ai.com/common-ui-plus/en/components/fixture).
