-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvite.config.ts
More file actions
60 lines (56 loc) · 1.6 KB
/
vite.config.ts
File metadata and controls
60 lines (56 loc) · 1.6 KB
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
/// <reference types="vitest" />
import 'dotenv/config'
import { resolve } from 'node:path'
import { defineConfig, type UserConfig } from 'vite'
import { builtinModules } from 'module'
import { spawnSync } from 'node:child_process'
const allExternal = [...builtinModules, ...builtinModules.map((m) => `node:${m}`)]
function copyToHA() {
let enabled = true
return {
name: 'copy-to-ha',
description: 'Copy files to Home Assistant',
config(config: UserConfig, { command }: { command: string }) {
if (process.env.HA_SCP_TARGET && command !== 'build' && !config.build?.watch) {
console.warn(
'The copy-to-ha plugin can only be used in "build" mode and "watch". Skipping...',
)
enabled = false
return
}
if (process.env.HA_SCP_TARGET) {
console.log(`Copying files to Home Assistant enabled...: ${process.env.HA_SCP_TARGET}`)
}
},
closeBundle: async () => {
if (!enabled || !process.env.HA_SCP_TARGET) {
return
}
console.log('Copying files to Home Assistant...')
spawnSync('scp', ['dist/sc-custom-cards.js', process.env.HA_SCP_TARGET])
console.log('Files copied to Home Assistant.')
},
}
}
export default defineConfig({
define: {
'process.env': {},
},
resolve: {
alias: {
'@': resolve(__dirname, 'src'),
},
},
plugins: [copyToHA()],
build: {
target: 'esnext',
rollupOptions: {
external: ['fsevents', ...allExternal],
},
lib: {
entry: resolve(__dirname, 'src/index.ts'),
formats: ['es'],
fileName: 'sc-custom-cards',
},
},
})