-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
99 lines (89 loc) · 3.19 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
const vite = require('vite');
import laravel from 'laravel-vite-plugin';
import { viteStaticCopy } from 'vite-plugin-static-copy'
import fs from 'fs-extra';
import path from 'path';
const folder = {
src: "resources/", // source files
src_assets: "resources/", // source assets files
dist: "public/", // build files
dist_assets: "public/build/" //build assets files
};
export default vite.defineConfig({
build: {
manifest: true,
rtl: true,
outDir: 'public/build/',
cssCodeSplit: true,
rollupOptions: {
output: {
assetFileNames: (css) => {
if (css.name.split('.').pop() == 'css') {
return 'css/' + `[name]` + '.min.' + 'css';
} else {
return 'icons/' + css.name;
}
},
entryFileNames: 'js/' + `[name]` + `.js`,
},
},
},
plugins: [
laravel(
{
input: [
'resources/scss/bootstrap.scss',
'resources/scss/icons.scss',
'resources/scss/app.scss',
'resources/scss/custom.scss',
],
refresh: true
}
),
viteStaticCopy({
targets: [
{
src: 'resources/fonts',
dest: ''
},
{
src: 'resources/images',
dest: ''
},
{
src: 'resources/js',
dest: ''
},
{
src: 'resources/json',
dest: ''
},
]
}),
{
name: 'copy-specific-packages',
async writeBundle() {
const outputPath = path.resolve(__dirname, folder.dist_assets); // Adjust the destination path
const configPath = path.resolve(__dirname, 'package-copy-config.json');
try {
const configContent = await fs.readFile(configPath, 'utf-8');
const { packagesToCopy } = JSON.parse(configContent);
for (const packageName of packagesToCopy) {
const destPackagePath = path.join(outputPath, 'libs', packageName);
const sourcePath = (fs.existsSync(path.join(__dirname, 'node_modules', packageName + "/dist"))) ?
path.join(__dirname, 'node_modules', packageName + "/dist")
: path.join(__dirname, 'node_modules', packageName);
try {
await fs.access(sourcePath, fs.constants.F_OK);
await fs.copy(sourcePath, destPackagePath);
} catch (error) {
console.error(`Package ${packageName} does not exist.`);
}
}
} catch (error) {
console.error('Error copying and renaming packages:', error);
}
},
},
],
});