-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathvite.config.js
166 lines (140 loc) · 3.87 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import Pages from 'vite-plugin-pages'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import path from "path"
//import viteCompression from 'vite-plugin-compression';
import Icons from 'unplugin-icons/vite'
import IconsResolver from 'unplugin-icons/resolver'
//import nodePolyfills from 'vite-plugin-node-stdlib-browser'
//import ViteCompress from "vite-plugin-compress"
import ViteCompression2 from 'vite-plugin-compression2'
import zlib from "node:zlib"
import VitePreload from "vite-plugin-preload";
import { visualizer } from "rollup-plugin-visualizer";
import dynamicImport from 'vite-plugin-dynamic-import'
import legacy from '@vitejs/plugin-legacy'
import { argv } from 'process'
import basicSsl from '@vitejs/plugin-basic-ssl'
import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill'
import { createHtmlPlugin } from 'vite-plugin-html'
//console.log("process.env.====>", process.env.BOTFI_PLATFORM)
const botfiPlatform = (process.env.BOTFI_PLATFORM || "").trim()
const env = process.env.NODE_ENV
console.log("Bot Platform==>", botfiPlatform)
console.log("process.env.NODE_ENV==>", env)
let htmlPuginData = { injectScript: "" }
const plugins = [
vue(),
dynamicImport(),
VitePreload(),
visualizer(),
AutoImport(),
legacy({
targets: ['defaults', 'not IE 11', 'chrome>=60', "chromeAndroid>=60"],
modernTargets: ['defaults', 'chrome>=60',"chromeAndroid>=60"],
polyfills: true,
modernPolyfills: true,
externalSystemJS: true
}),
Pages({
importMode: (botfiPlatform == 'capacitor') ? 'sync': 'async'
}),
Icons({ compiler: 'vue3' }),
Components({
directoryAsNamespace: false,
dirs: ['src/components', 'src/layouts'],
extensions: ['vue'],
dts: true,
include: [/\.vue$/, /\.vue\?vue/],
resolvers: [IconsResolver({ prefix: 'ic' })],
}),
]
if (env == "production") {
if(botfiPlatform != 'capacitor'){
plugins.push(...[
ViteCompression2({
include: /(\.(html|css|jsx?|ts|json|txt|woff|tff|woff2|otf))$/i,
algorithm: 'brotliCompress',
threshold: 1000,
compressionOptions: {
[zlib.constants.BROTLI_PARAM_QUALITY]: 11,
},
filename: "[path][base].br"
})
]
)
}
if(botfiPlatform == "telegram"){
htmlPuginData = {
injectScript: `<script src="https://telegram.org/js/telegram-web-app.js"></script>`,
}
}
} else {
htmlPuginData = {
injectScript: `<script src="https://telegram.org/js/telegram-web-app.js"></script>`,
}
plugins.push(...[
basicSsl()
])
}
plugins.push(createHtmlPlugin({
minify: false,
entry: `src/main_${botfiPlatform}.js`,
template: './index.html',
inject: {
data: htmlPuginData
}
}));
export default defineConfig({
//base: '/',
rollupInputOptions: {
input: path.resolve(__dirname, `/src/main_${botfiPlatform}.js`)
},
plugins,
resolve: {
alias: {
'@': path.join(__dirname, '/src/'),
'~': __dirname+"/node_modules/",
},
},
optimizeDeps: {
exclude: [
"whatwg-fetch",
"animate.css"
],
esbuildOptions: {
// Node.js global to browser globalThis
define: {
global: 'globalThis'
},
// Enable esbuild polyfill plugins
plugins: [
NodeGlobalsPolyfillPlugin({
buffer: true
})
]
}
},
build: {
polyfillDynamicImport: true,
minify: false,
target: "es2020", // Enable Big integer literals
commonjsOptions: {
transformMixedEsModules: true,
}
},
server: {
host: '0.0.0.0',///'botfi-dev.com',
port: 5173,
strictPort: true,
//https: true,
headers: {
"localtonet-skip-warning": "true"
}
},
define: {
//"global": {},
},
})