-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathvite.config.ts
169 lines (163 loc) · 5.84 KB
/
vite.config.ts
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
167
168
169
import { defineConfig } from 'vite';
import path from 'path';
import fs from 'fs';
import packageJson from './package.json';
import VueDevTools from 'vite-plugin-vue-devtools'
import vue from '@vitejs/plugin-vue';
import legacy from '@vitejs/plugin-legacy'
import vueI18n from '@intlify/unplugin-vue-i18n/vite';
import { del } from '@kineticcafe/rollup-plugin-delete';
import { viteStaticCopy } from 'vite-plugin-static-copy'
import { DominionContentGenerate, HandleLocaleGenerateAndMerge } from './plugins/vite-dominion-content';
// On-demand components auto importing for Vue.
//import UnPluginVueComponents from 'unplugin-vue-components/vite';
const devServerPort = 5173;
const publicationDir = 'docs';
export default defineConfig( ({ mode}) => {
//console.log(process.argv)
if (mode === 'production' || mode === 'development') {
// mergeJSONLanguageFiles();
DominionContentGenerate('docs');
let ArgGenLocale = 'Merge';
if (process.argv.slice(3)[0] == 'Gen') {
ArgGenLocale = 'Gen&Merge';
}
HandleLocaleGenerateAndMerge(ArgGenLocale, 'docs')
}
let baseDir = './'
return {
appType: 'spa',
base: baseDir,
publicDir: false, // Do not use publicDir feature to avoid duplcation of all image and pdf files.
/*
Do not use publicDir feature to avoid duplcation of all image and pdf files.
*/
define: {
Pkgejson_Version: JSON.stringify(packageJson.version),
Pkgejson_Name: JSON.stringify(packageJson.name),
Pkgejson_URL: JSON.stringify(packageJson.repository.url),
Pkgejson_Date: JSON.stringify(new Date().toLocaleDateString(undefined, { year: 'numeric', month: 'numeric' }))
},
plugins: [
{ name: 'add-datetime',
/* vite hook the plugin should use: transformIndexHtml()
https://vitejs.dev/guide/api-plugin#universal-hooks */
transformIndexHtml(html) {
const datetime = new Date().toLocaleString('fr-FR', { dateStyle: 'long', timeStyle: 'medium' });
//console.log('\nGenerate Date and Time: ', datetime);
return html.replace(/id="datetime">/g, `id="datetime">${datetime}`);
}
},
{
name: 'copy-index',
/* vite hook the plugin should use: closeBundle()
https://vitejs.dev/guide/api-plugin#universal-hooks */
closeBundle() {
try {
fs.copyFileSync(
path.resolve(__dirname, './'+ publicationDir +'/index.html'),
path.resolve(__dirname, './'+ publicationDir +'/404.html'))
} catch (err) {
if (err) throw err;
console.log('index.html copied successfully');
}
}
},
vue(),
mode == 'development' ? VueDevTools() : [],
legacy({ targets: ['defaults'] }),
vueI18n({
include: path.resolve(__dirname, './'+ publicationDir +'/locales/*.json'),
compositionOnly: true,
fullInstall: true,
allowDynamic: true,
runtimeOnly: false
}),
del({
targets: [publicationDir +'/*',
'!'+ publicationDir +'/rules',
'!'+ publicationDir +'/rules.fr',
'!'+ publicationDir +'/rules.de',
'!'+ publicationDir +'/img',
'!'+ publicationDir +'/favicon.ico',
'!'+ publicationDir +'/dominion-content.js',
'!'+ publicationDir +'/locales',
'!'+ publicationDir +'/locales/??.json',
'!'+ publicationDir +'/CNAME',
'!'+ publicationDir +'/ads.txt'],
verbose: false
}),
viteStaticCopy({
targets: [ { src: 'styles/normalize-v8.css', dest: 'assets/' }
]
})
],
optimizeDeps: {
include: ['vue', 'vue-i18n']
},
resolve: {
//extensions: ['.ts', '.vue'],
alias: {
// Alias pour les modules non-Esbuild compatibles avec Vite
//'@': fileURLToPath(new URL('./src', import.meta.url)),
//'vue-i18n': 'vue-i18n/dist/vue-i18n.esm-bundler.js',
//'vue': 'vue/dist/vue.esm-bundler.js',
},
},
build: {
minify: true,
outDir: publicationDir,
emptyOutDir: false,
sourcemap: false,
chunkSizeWarningLimit: 2000,
rollupOptions: {
output: {
entryFileNames: 'assets/[name]-[hash].js',
chunkFileNames: 'assets/[name]-[hash].js',
assetFileNames: 'assets/[name]-[hash][extname]'
}
},
},
server: {
open: '/',
proxy: {
'^/$': {
target: 'http://localhost:' + devServerPort,
rewrite: () => '/index.html',
},
'/dominion-content.js': {
target: 'http://localhost:' + devServerPort,
rewrite: (path) => path.replace(/^\/dominion-content.js/, '/'+ publicationDir +'/dominion-content.js'),
},
'/normalize': {
target: 'http://localhost:' + devServerPort,
rewrite: (path) => path.replace(/^\/normalize/, '/'+ publicationDir +'/normalize'),
},
'/favicon.ico': {
target: 'http://localhost:' + devServerPort,
rewrite: (path) => path.replace(/^\/favicon.ico/, '/'+ publicationDir +'/favicon.ico'),
},
'/img': {
target: 'http://localhost:' + devServerPort,
rewrite: (path) => path.replace(/^\/img/, '/'+ publicationDir +'/img'),
},
'/rules': {
target: 'http://localhost:' + devServerPort,
rewrite: (path) => path.replace(/^\/rules/, '/'+ publicationDir +'/rules'),
},
'/locales': {
target: 'http://localhost:' + devServerPort,
rewrite: (path) => path.replace(/^\/locales/, '/'+ publicationDir +'/locales'),
},
'/?': {
target: 'http://localhost:' + devServerPort,
// rewrite: (path) => path.replace(/^\/?/, '/docs/index.html?'),
rewrite: (path) => path.replace(/^\/?/, '/index.html?'),
},
},
},
preview: {
proxy: { }
}
}
});