-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
110 lines (105 loc) · 2.77 KB
/
vite.config.js
File metadata and controls
110 lines (105 loc) · 2.77 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
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
import { defineConfig } from 'vite';
import { visualizer } from 'rollup-plugin-visualizer';
import imagemin from 'vite-plugin-imagemin';
import fs from 'fs';
import path from 'path';
// Custom plugin for AngularJS template cache
function angularTemplateCache(options = {}) {
const { templateDir = 'packages/templates', prefix = '' } = options;
return {
name: 'angular-template-cache',
transform(code, id) {
if (id.endsWith('.html') && id.includes(templateDir)) {
const template = fs.readFileSync(id, 'utf-8');
const templatePath = path.relative(templateDir, id);
const moduleId = prefix + templatePath;
return {
code: `
angular.module('ng').run(['$templateCache', function($templateCache) {
$templateCache.put('${moduleId}', '${template.replace(/'/g, "\\'").replace(/\n/g, '\\n')}');
}]);
export default '${moduleId}';
`,
map: null
};
}
return null;
},
handleHotUpdate({ file, server }) {
if (file.endsWith('.html') && file.includes(templateDir)) {
const template = fs.readFileSync(file, 'utf-8');
const templatePath = path.relative(templateDir, file);
const moduleId = prefix + templatePath;
const mod = server.moduleGraph.getModuleById(file);
if (mod) {
server.ws.send({
type: 'custom',
event: 'angular-template-update',
data: { moduleId, template }
});
}
}
}
};
}
export default defineConfig({
root: '.',
build: {
outDir: 'dist',
assetsDir: 'assets',
rollupOptions: {
input: {
main: '/index.html'
},
output: {
entryFileNames: 'js/[name]-[hash].js',
chunkFileNames: 'js/[name]-[hash].js',
assetFileNames: 'assets/[name]-[hash].[ext]'
}
},
plugins: [
visualizer({
filename: 'dist/stats.html',
open: false,
gzipSize: true,
brotliSize: true
})
]
},
server: {
port: 8080,
open: false,
proxy: {
'/api': {
target: 'http://localhost:3000',
changeOrigin: true
}
},
hmr: {
overlay: true
}
},
resolve: {
alias: {
'@app': '/apps/main-app/app',
'@packages': '/packages',
'@templates': '/packages/templates'
}
},
plugins: [
angularTemplateCache({
templateDir: 'packages/templates',
prefix: ''
}),
imagemin({
gifsicle: { optimizationLevel: 7 },
optipng: { optimizationLevel: 7 },
mozjpeg: { quality: 80 },
pngquant: { quality: [0.8, 0.9] },
svgo: true
})
],
optimizeDeps: {
include: ['angular', 'angular-route', 'angular-animate', 'angular-loader', 'ngstorage']
}
});