-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
94 lines (82 loc) · 3.45 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
import { defineConfig } from 'vite';
import laravel, { refreshPaths } from 'laravel-vite-plugin';
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 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: [
...refreshPaths,
'resources/views/**',
],
}
),
{
name: 'copy-specific-packages',
async writeBundle() {
try {
// Copy images, json, fonts, and js
await Promise.all([
fs.copy(folder.src_assets + 'fonts', folder.dist_assets + 'fonts'),
fs.copy(folder.src_assets + 'images', folder.dist_assets + 'images'),
fs.copy(folder.src_assets + 'js', folder.dist_assets + 'js'),
fs.copy(folder.src_assets + 'json', folder.dist_assets + 'json'),
]);
} catch (error) {
console.error('Error copying assets:', error);
}
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);
}
},
},
],
});