@varlet/import-resolver 3.0.7 → 3.1.0-alpha.1709537939980

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +148 -0
  2. package/README.zh-CN.md +146 -0
  3. package/package.json +2 -2
package/README.md ADDED
@@ -0,0 +1,148 @@
1
+ # Varlet Auto Import Resolver
2
+
3
+ English | [简体中文](./README.zh-CN.md)
4
+
5
+ `@varlet/import-resolver` is a resolver for [unplugin-vue-components](https://github.com/unplugin/unplugin-vue-components) that enables on-demand importing of Varlet components.
6
+
7
+ ## Features
8
+
9
+ - Supports `Vite`, `Webpack`, `Vue CLI`, `Rollup`, `esbuild`, and more.
10
+ - Automatically imports the corresponding CSS styles for the components.
11
+ - Supports SSR (Server-Side Rendering).
12
+
13
+ ## Automatic Import
14
+
15
+ via plugin
16
+ [unplugin-vue-components](https://github.com/antfu/unplugin-vue-components) and
17
+ [unplugin-auto-import](https://github.com/antfu/unplugin-auto-import)
18
+ Implement components to automatically import on demand, This is our most recommended way.
19
+
20
+ ### Install Plugin
21
+
22
+ ```shell
23
+ # npm
24
+ npm i @varlet/import-resolver unplugin-vue-components unplugin-auto-import -D
25
+
26
+ # yarn
27
+ yarn add @varlet/import-resolver unplugin-vue-components unplugin-auto-import -D
28
+
29
+ # pnpm
30
+ pnpm add @varlet/import-resolver unplugin-vue-components unplugin-auto-import -D
31
+ ```
32
+
33
+ ### Vite
34
+
35
+ ```js
36
+ // vite.config.js
37
+ import vue from '@vitejs/plugin-vue'
38
+ import components from 'unplugin-vue-components/vite'
39
+ import autoImport from 'unplugin-auto-import/vite'
40
+ import { VarletImportResolver } from '@varlet/import-resolver'
41
+ import { defineConfig } from 'vite'
42
+
43
+ export default defineConfig({
44
+ plugins: [
45
+ vue(),
46
+ components({
47
+ resolvers: [VarletImportResolver()]
48
+ }),
49
+ autoImport({
50
+ resolvers: [VarletImportResolver({ autoImport: true })]
51
+ })
52
+ ]
53
+ })
54
+ ```
55
+
56
+ ### Vue CLI
57
+
58
+ ```js
59
+ // vue.config.js
60
+ const Components = require('unplugin-vue-components/webpack')
61
+ const AutoImport = require('unplugin-auto-import/webpack')
62
+ const { VarletImportResolver } = require('@varlet/import-resolver')
63
+
64
+ module.exports = {
65
+ configureWebpack: {
66
+ plugins: [
67
+ Components.default({
68
+ resolvers: [VarletImportResolver()]
69
+ }),
70
+ AutoImport.default({
71
+ resolvers: [VarletImportResolver({ autoImport: true })]
72
+ })
73
+ ]
74
+ }
75
+ }
76
+ ```
77
+
78
+ ### Typescript configuration note
79
+
80
+ In order to get good IDE syntax highlighting,
81
+ please make sure that the type declaration files generated by the above two plugins are include by `typescript`,
82
+ which can be configured as follows in `tsconfig.json`:
83
+
84
+ ```json
85
+ {
86
+ "include": ["auto-imports.d.ts", "components.d.ts"]
87
+ }
88
+ ```
89
+
90
+ ### Manual import
91
+
92
+ Each component is a `Vue plugin` and consists of `component logic` and `style files`, which are manually imported and used as follows.
93
+
94
+ ```js
95
+ import App from './App.vue'
96
+ import { createApp } from 'vue'
97
+ import { Button } from '@varlet/ui'
98
+ import '@varlet/ui/es/button/style/index'
99
+
100
+ createApp(App).use(Button)
101
+ ```
102
+
103
+ OR
104
+
105
+ ```html
106
+ <script setup>
107
+ import { Button as VarButton } from '@varlet/ui'
108
+ import '@varlet/ui/es/button/style/index'
109
+ </script>
110
+
111
+ <template>
112
+ <var-button>Say Hello</var-button>
113
+ </template>
114
+ ```
115
+
116
+ ### Manual import and automatic import comparison
117
+
118
+ #### Comparison-Manual import
119
+
120
+ ```html
121
+ <script setup>
122
+ import { Button as VarButton, Snackbar } from '@varlet/ui'
123
+ import '@varlet/ui/es/button/style/index'
124
+ import '@varlet/ui/es/snackbar/style/index'
125
+
126
+ function handleClick() {
127
+ Snackbar('Hello!')
128
+ }
129
+ </script>
130
+
131
+ <template>
132
+ <var-button @click="handleClick">Say Hello</var-button>
133
+ </template>
134
+ ```
135
+
136
+ #### Comparison-Automatic import
137
+
138
+ ```html
139
+ <script setup>
140
+ function handleClick() {
141
+ Snackbar('Hello!')
142
+ }
143
+ </script>
144
+
145
+ <template>
146
+ <var-button @click="handleClick">Say Hello</var-button>
147
+ </template>
148
+ ```
@@ -0,0 +1,146 @@
1
+ # Varlet Auto Import Resolver
2
+
3
+ [English](./README.md) | 简体中文
4
+
5
+ `@varlet/import-resolver` 是 [unplugin-vue-components](https://github.com/unplugin/unplugin-vue-components) 的一个解析器,用于实现 Varlet 按需引入。
6
+
7
+ ## 特性
8
+
9
+ - 支持 `Vite`, `Webpack`, `Vue CLI`, `Rollup`, `esbuild` 等
10
+ - 支持自动引入组件对应的 CSS 样式
11
+ - 支持 SSR(服务端渲染)
12
+
13
+ ## 自动引入
14
+
15
+ 通过插件
16
+ [unplugin-vue-components](https://github.com/antfu/unplugin-vue-components) 和
17
+ [unplugin-auto-import](https://github.com/antfu/unplugin-auto-import)
18
+ 实现组件自动按需导入,这也是我们最推荐的方式。
19
+
20
+ ## 安装插件
21
+
22
+ ```shell
23
+ # npm
24
+ npm i @varlet/import-resolver unplugin-vue-components unplugin-auto-import -D
25
+
26
+ # yarn
27
+ yarn add @varlet/import-resolver unplugin-vue-components unplugin-auto-import -D
28
+
29
+ # pnpm
30
+ pnpm add @varlet/import-resolver unplugin-vue-components unplugin-auto-import -D
31
+ ```
32
+
33
+ ### Vite
34
+
35
+ ```js
36
+ // vite.config.js
37
+ import vue from '@vitejs/plugin-vue'
38
+ import components from 'unplugin-vue-components/vite'
39
+ import autoImport from 'unplugin-auto-import/vite'
40
+ import { VarletImportResolver } from '@varlet/import-resolver'
41
+ import { defineConfig } from 'vite'
42
+
43
+ export default defineConfig({
44
+ plugins: [
45
+ vue(),
46
+ components({
47
+ resolvers: [VarletImportResolver()]
48
+ }),
49
+ autoImport({
50
+ resolvers: [VarletImportResolver({ autoImport: true })]
51
+ })
52
+ ]
53
+ })
54
+ ```
55
+
56
+ ### Vue CLI
57
+
58
+ ```js
59
+ // vue.config.js
60
+ const Components = require('unplugin-vue-components/webpack')
61
+ const AutoImport = require('unplugin-auto-import/webpack')
62
+ const { VarletImportResolver } = require('@varlet/import-resolver')
63
+
64
+ module.exports = {
65
+ configureWebpack: {
66
+ plugins: [
67
+ Components.default({
68
+ resolvers: [VarletImportResolver()]
69
+ }),
70
+ AutoImport.default({
71
+ resolvers: [VarletImportResolver({ autoImport: true })]
72
+ })
73
+ ]
74
+ }
75
+ }
76
+ ```
77
+
78
+ ### Typescript 配置注意
79
+
80
+ 为了得到良好的 IDE 语法高亮,请确保上述两个插件生成的类型声明文件被 `typescript` 识别,可在 `tsconfig.json` 中进行如下配置:
81
+
82
+ ```json
83
+ {
84
+ "include": ["auto-imports.d.ts", "components.d.ts"]
85
+ }
86
+ ```
87
+
88
+ ### 手动引入
89
+
90
+ 每一个组件都是一个 `Vue插件`,并由 `组件逻辑` 和 `样式文件` 组成,手动引入的使用方式如下。
91
+
92
+ ```js
93
+ import App from './App.vue'
94
+ import { createApp } from 'vue'
95
+ import { Button } from '@varlet/ui'
96
+ import '@varlet/ui/es/button/style/index'
97
+
98
+ createApp(App).use(Button)
99
+ ```
100
+
101
+
102
+
103
+ ```html
104
+ <script setup>
105
+ import { Button as VarButton } from '@varlet/ui'
106
+ import '@varlet/ui/es/button/style/index'
107
+ </script>
108
+
109
+ <template>
110
+ <var-button>说你好</var-button>
111
+ </template>
112
+ ```
113
+
114
+ ### 手动引入和自动引入对比
115
+
116
+ #### 对比-手动引入
117
+
118
+ ```html
119
+ <script setup>
120
+ import { Button as VarButton, Snackbar } from '@varlet/ui'
121
+ import '@varlet/ui/es/button/style/index'
122
+ import '@varlet/ui/es/snackbar/style/index'
123
+
124
+ function handleClick() {
125
+ Snackbar('你好!')
126
+ }
127
+ </script>
128
+
129
+ <template>
130
+ <var-button @click="handleClick">说你好</var-button>
131
+ </template>
132
+ ```
133
+
134
+ #### 对比-自动引入
135
+
136
+ ```html
137
+ <script setup>
138
+ function handleClick() {
139
+ Snackbar('你好!')
140
+ }
141
+ </script>
142
+
143
+ <template>
144
+ <var-button @click="handleClick">说你好</var-button>
145
+ </template>
146
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/import-resolver",
3
- "version": "3.0.7",
3
+ "version": "3.1.0-alpha.1709537939980",
4
4
  "type": "module",
5
5
  "main": "lib/index.cjs",
6
6
  "module": "lib/index.js",
@@ -35,7 +35,7 @@
35
35
  "url": "https://github.com/varletjs/varlet/issues"
36
36
  },
37
37
  "dependencies": {
38
- "@varlet/shared": "3.0.7"
38
+ "@varlet/shared": "3.1.0-alpha.1709537939980"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/node": "^18.7.18",