Skip to content

Commit e7f3602

Browse files
committed
feat(select): auto-inject css with js, don't need to import separately the css file
1 parent 360c45f commit e7f3602

12 files changed

+20
-30
lines changed

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ Use it in your Vue 3 app:
4747
import { ref } from "vue";
4848
import VueSelect from "vue3-select-component";
4949
50-
import "vue3-select-component/dist/style.css";
51-
5250
const option = ref("");
5351
</script>
5452
@@ -77,8 +75,6 @@ It also leverages the power of generics to provide types for additional properti
7775
import { ref } from "vue";
7876
import VueSelect, { type Option } from "vue3-select-component";
7977
80-
import "vue3-select-component/dist/style.css";
81-
8278
type UserOption = Option<number> & { username: string };
8379
8480
const selectedUser = ref<number>();

docs/demo/custom-option-slot.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ const selected = ref("");
7474

7575
```vue
7676
<script setup lang="ts">
77-
import "vue3-select-component/dist/style.css";
78-
7977
import { ref } from "vue";
8078
import VueSelect from "vue3-select-component";
8179

docs/demo/multiple-select.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ Selected value(s): **{{ selected.length ? selected.join(", ") : "none" }}**
3434

3535
```vue
3636
<script setup lang="ts">
37-
import "vue3-select-component/dist/style.css";
38-
3937
import { ref } from "vue";
4038
import VueSelect from "vue3-select-component";
4139

docs/demo/pre-selected-values.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ const multiSelected = ref(["option_3", "option_5"]);
4747
## Demo source-code
4848

4949
```vue
50-
<script setup>
51-
import "vue3-select-component/dist/style.css";
52-
50+
<script setup lang="ts">
5351
import { ref } from "vue";
5452
import VueSelect from "vue3-select-component";
5553

docs/demo/single-select.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ Selected value: **{{ selected || "none" }}**
2929

3030
```vue
3131
<script setup lang="ts">
32-
import "vue3-select-component/dist/style.css";
33-
3432
import { ref } from "vue";
3533
import VueSelect from "vue3-select-component";
3634

docs/demo/with-complex-menu-filter.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ function switchFilter() {
6767

6868
```vue
6969
<script setup lang="ts">
70-
import "vue3-select-component/dist/style.css";
71-
7270
import { computed, ref } from "vue";
7371
import VueSelect from "vue3-select-component";
7472

docs/demo/with-menu-header.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ const selected = ref("");
5151

5252
```vue
5353
<script setup>
54-
import "vue3-select-component/dist/style.css";
55-
5654
import { ref } from "vue";
5755
import VueSelect from "vue3-select-component";
5856

docs/getting-started.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ Import the component with the styling, and use it in your Vue 3 application:
3636

3737
```vue
3838
<script setup lang="ts">
39-
import "vue3-select-component/dist/style.css";
40-
4139
import { ref } from "vue";
4240
import VueSelect from "vue3-select-component";
4341
@@ -70,8 +68,6 @@ To enable the multiselect feature, all you need to do is:
7068

7169
```vue
7270
<script setup>
73-
import "vue3-select-component/dist/style.css";
74-
7571
import { ref } from "vue";
7672
import VueSelect from "vue3-select-component";
7773

docs/styling.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ title: 'Styling'
66

77
Vue 3 Select Component provides 2 types of customization available in the component.
88

9+
::: tip
10+
The default component styling is already included with the VueSelect component, you don't need to import any CSS file to make it work.
11+
:::
12+
913
## CSS variables
1014

1115
CSS variables is the easiest way to customize the component style but provides less flexibility over your design. When importing the component, you will notice that CSS variables are injected into the `:root` scope and are prefixed with `--vs-select-[...]`.

package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@
1919
"types": "./dist/index.d.ts",
2020
"import": "./dist/index.es.js",
2121
"require": "./dist/index.umd.js"
22-
},
23-
"./dist/style.css": {
24-
"types": "./dist/style.css",
25-
"import": "./dist/style.css",
26-
"require": "./dist/style.css"
2722
}
2823
},
2924
"main": "dist/index.umd.js",
@@ -65,6 +60,7 @@
6560
"sass": "1.77.6",
6661
"typescript": "5.5.2",
6762
"vite": "5.3.2",
63+
"vite-plugin-css-injected-by-js": "3.5.1",
6864
"vite-plugin-dts": "3.9.1",
6965
"vite-plugin-vue-devtools": "7.3.5",
7066
"vitepress": "1.2.3",

vite.config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@ import { type UserConfig, defineConfig } from "vite";
55
import vue from "@vitejs/plugin-vue";
66
import vueDevtools from "vite-plugin-vue-devtools";
77
import dts from "vite-plugin-dts";
8+
import cssInject from "vite-plugin-css-injected-by-js";
89

910
const resolve = (path: string) => fileURLToPath(new URL(path, import.meta.url));
1011

1112
// https://vitejs.dev/config/
1213
export default defineConfig((configEnv) => {
13-
// Default shared config by all modes.
14+
// Default config shared config by all modes.
1415
const config: UserConfig = {
1516
plugins: [vue()],
16-
resolve: {
17-
alias: { "@": resolve("./src") },
18-
},
17+
resolve: { alias: { "@": resolve("./src") } },
1918
};
2019

2120
// When running vitest, add the test config.
@@ -36,6 +35,7 @@ export default defineConfig((configEnv) => {
3635

3736
plugins: [
3837
...config.plugins!,
38+
cssInject(),
3939
dts({ tsconfigPath: "tsconfig.build.json", cleanVueFileName: true }),
4040
],
4141

0 commit comments

Comments
 (0)