Skip to content

Commit 21efadf

Browse files
committed
🔧 update vite config
1 parent 9bc5954 commit 21efadf

File tree

4 files changed

+58
-67
lines changed

4 files changed

+58
-67
lines changed

example/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createApp } from 'vue';
1+
import { createApp } from 'vue-demi';
22
import 'virtual:windi.css';
33
import './style.css';
44

package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
"test": "jest",
3636
"dev": "vite",
3737
"dev:docs": "vitepress dev docs --port 4000",
38-
"build": "yarn clean && yarn pretty && vite build --mode library && yarn type",
38+
"build:lib": "yarn clean && yarn pretty && vite build --mode lib && yarn type",
3939
"build:docs": "yarn clean && vitepress build docs",
4040
"build:example": "yarn clean && yarn pretty && vite build --mode example",
41-
"release": "np"
41+
"release": "yarn build:lib && np"
4242
},
4343
"dependencies": {
4444
"vue-demi": "^0.11.2"
@@ -63,13 +63,11 @@
6363
"vite": "^2.3.5",
6464
"vite-plugin-windicss": "^1.0.4",
6565
"vitepress": "^0.15.3",
66-
"vue": "^3.0.11",
6766
"vue-jest": "^5.0.0-alpha.10",
6867
"windicss": "^3.1.3"
6968
},
7069
"peerDependencies": {
71-
"@vue/composition-api": "^1.0.0-rc.1",
72-
"vue": ">= 2.6 || >=3.0.0"
70+
"@vue/composition-api": "^1.0.0-rc.1"
7371
},
7472
"peerDependenciesMeta": {
7573
"@vue/composition-api": {

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import {
2424
Entries,
2525
UnknownObject,
2626
Result,
27-
Args,
2827
ArgsObject,
2928
Entry,
3029
Error,

vite.config.js

Lines changed: 54 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,67 @@
11
import vue from '@vitejs/plugin-vue';
22
import WindiCSS from 'vite-plugin-windicss';
3-
43
import { resolve } from 'path';
54

6-
const libraryName = 'vue-tiny-validate';
7-
8-
const example = resolve(__dirname, 'example');
9-
const exampleOutDir = resolve(__dirname, 'dist-example');
10-
const library = resolve(__dirname, 'src');
11-
const libraryEntry = resolve(__dirname, `src/index.ts`);
12-
const libraryOutDir = resolve(__dirname, 'dist');
5+
const LIBRARY_NAME = 'vue-tiny-validate';
136

14-
export default ({ command, mode }) => {
15-
const exampleOption = {
16-
plugins: [vue(), WindiCSS()],
17-
root: example,
18-
resolve: {
19-
alias: {
20-
[libraryName]: library,
21-
},
7+
const settings = {
8+
plugins: [vue(), WindiCSS()],
9+
root: resolve(__dirname, 'example'),
10+
resolve: {
11+
alias: {
12+
[LIBRARY_NAME]: resolve(__dirname, 'src'),
2213
},
23-
};
24-
25-
// dev mode
26-
if (command === 'serve') {
27-
return {
28-
...exampleOption,
29-
server: {
30-
port: 3456,
31-
},
32-
};
33-
}
14+
},
15+
};
3416

35-
// otherwise, build mode
17+
// dev
18+
const dev = {
19+
...settings,
20+
server: {
21+
port: 3456,
22+
},
23+
};
3624

37-
// build example
38-
if (mode === 'example') {
39-
return {
40-
...exampleOption,
41-
build: {
42-
outDir: exampleOutDir,
43-
},
44-
};
45-
}
25+
// build: example
26+
const buildExample = {
27+
...settings,
28+
build: {
29+
outDir: resolve(__dirname, 'dist-example'),
30+
},
31+
};
4632

47-
// build library
48-
if (mode === 'library') {
49-
return {
50-
plugin: [vue()],
51-
build: {
52-
lib: {
53-
entry: libraryEntry,
54-
name: libraryName,
55-
fileName: 'index',
56-
formats: ['es', 'cjs', 'umd'],
57-
},
58-
rollupOptions: {
59-
external: ['vue', 'vue-demi'],
60-
output: {
61-
globals: {
62-
vue: 'Vue',
63-
'vue-demi': 'VueDemi',
64-
},
65-
},
33+
// build: lib
34+
const buildLib = {
35+
plugin: [vue()],
36+
build: {
37+
lib: {
38+
entry: resolve(__dirname, `src/index.ts`),
39+
name: LIBRARY_NAME,
40+
fileName: 'index',
41+
formats: ['es', 'cjs', 'umd'],
42+
},
43+
rollupOptions: {
44+
external: ['vue', 'vue-demi'],
45+
output: {
46+
globals: {
47+
vue: 'Vue',
48+
'vue-demi': 'VueDemi',
6649
},
67-
outDir: libraryOutDir,
6850
},
69-
};
70-
}
51+
},
52+
outDir: resolve(__dirname, 'dist'),
53+
},
54+
};
7155

72-
return {};
56+
export default ({ command, mode }) => {
57+
switch (true) {
58+
case command === 'serve':
59+
return dev;
60+
case command === 'build' && mode === 'example':
61+
return buildExample;
62+
case command === 'build' && mode === 'lib':
63+
return buildLib;
64+
default:
65+
return {};
66+
}
7367
};

0 commit comments

Comments
 (0)