forked from cloudforet-io/console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.js
83 lines (74 loc) · 2.7 KB
/
vite.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import path from 'path';
import process from 'process';
import glob from 'glob';
import fs from 'fs';
import vuePlugin from '@vitejs/plugin-vue2';
import { defineConfig, loadEnv } from 'vite';
import StylelintPlugin from 'vite-plugin-stylelint';
import VueTypeImports from 'vite-plugin-vue-type-imports';
const isPackageLinked = (packageName) => new Promise((resolve, reject) => {
if (!packageName) reject(new Error('No argument'));
const packagePath = path.resolve(__dirname, `./node_modules/${packageName}`)
glob(packagePath, (err, foundPaths) => {
if (err) reject(err)
if (!foundPaths.length) reject(new Error(packageName + ' package is not installed'));
foundPaths.forEach((foundPath) => {
fs.lstat(foundPath, (e, stats) => {
if (e) reject(e)
if (stats.isSymbolicLink()) {
resolve(true)
} else {
resolve(false)
}
})
})
})
})
export default defineConfig(async ({ command, mode }) => {
process.env = {...process.env, ...loadEnv(mode, process.cwd())};
if (command === 'serve') { console.log('serve mode') }
else { console.log('build mode') }
let mirinaeLinked = false;
if (command === 'serve') {
try {
mirinaeLinked = await isPackageLinked('@spaceone/design-system')
} catch (e) {
console.warn(e)
}
}
return {
optimizeDeps: {
include: mirinaeLinked ? ['@spaceone/design-system/tailwind.config.cjs'] : [],
},
plugins: [
vuePlugin(),
VueTypeImports(),
StylelintPlugin({
include: ['src/**/*.{css,vue,pcss,scss}'],
exclude: ['node_modules'],
lintOnStart: false,
emitErrorAsWarning: true,
}),
],
server: { port: 8080 },
preview: { port: 8080 },
test: {
globals: true,
environment: 'jsdom',
include: ['./src/**/__tests__/**/*.+(ts|js)'],
},
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
'@cloudforet/core-lib': path.resolve(__dirname, './packages/cloudforet/core-lib/dist/'),
'@cloudforet/language-pack': path.resolve(__dirname, './packages/cloudforet/language-pack/'),
vue: path.resolve(__dirname, './node_modules/vue/dist/vue.js'),
},
},
define: {
VITE_APP_VER: JSON.stringify(process.env.npm_package_version),
// Add env variables here
// Usage references => SignInLeftContainer.vue / env.d.ts
},
};
});