-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.mjs
More file actions
103 lines (92 loc) · 2.58 KB
/
Copy pathvite.config.mjs
File metadata and controls
103 lines (92 loc) · 2.58 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
// Standalone Vite build for the FancyAdmin package (replaces the old webpack.config.js).
// Consuming projects bundle FancyAdmin's assets from source via their own Vite config;
// this build is for developing/checking the package on its own. Output: dist/admin/.
import { defineConfig } from 'vite';
import path from 'path';
import fs from 'fs';
import { fileURLToPath } from 'url';
import autoprefixer from 'autoprefixer';
import inject from '@rollup/plugin-inject';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
// Copy fonts to where the compiled CSS references them. FontAwesome's @font-face uses
// its built-in "../webfonts" default and the Roboto faces use "../fonts" — both relative
// to the emitted CSS in dist/admin/, i.e. dist/{webfonts,fonts}.
const copyFonts = () => ({
name: 'copy-fancyadmin-fonts',
apply: 'build',
writeBundle() {
const copies = [
['node_modules/@fortawesome/fontawesome-pro/webfonts', 'dist/webfonts'],
['assets/fonts', 'dist/fonts'],
];
for (const [from, to] of copies) {
const src = path.resolve(__dirname, from);
const dest = path.resolve(__dirname, to);
if (fs.existsSync(src)) {
fs.cpSync(src, dest, { recursive: true });
}
}
},
});
export default defineConfig(({ mode }) => {
const isProduction = mode === 'production';
return {
root: path.resolve(__dirname, 'assets'),
build: {
outDir: path.resolve(__dirname, 'dist/admin'),
assetsDir: '',
emptyOutDir: true,
sourcemap: !isProduction,
minify: isProduction ? 'esbuild' : false,
cssMinify: isProduction,
manifest: true,
rollupOptions: {
input: path.resolve(__dirname, 'assets/js/admin.js'),
},
},
server: {
https: false,
host: 'localhost',
port: 3002,
strictPort: true,
},
css: {
devSourcemap: !isProduction,
preprocessorOptions: {
scss: {
quietDeps: true,
api: 'modern-compiler',
loadPaths: [
path.resolve(__dirname, 'node_modules'),
],
},
},
modules: {
generateScopedName: isProduction
? '[hash:base64]'
: '[path][local]__[hash:base64:5]',
localsConvention: 'camelCase',
},
postcss: {
plugins: [autoprefixer()],
},
},
plugins: [
// Inject jQuery globally (replaces webpack ProvidePlugin / expose-loader).
// select2's UMD self-registers on the global jQuery, so don't rewrite it there.
inject({
include: ['**/*.js'],
exclude: [/select2/],
$: 'jquery',
jQuery: 'jquery',
}),
copyFonts(),
],
optimizeDeps: {
include: ['jquery'],
},
define: {
'process.env.NODE_ENV': JSON.stringify(mode),
},
};
});