-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.images.mjs
71 lines (60 loc) · 2.08 KB
/
rollup.config.images.mjs
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
import { fileURLToPath } from 'url';
import path, { resolve } from 'path';
import { globSync } from 'glob';
import image from '@rollup/plugin-image';
import { defineConfig } from 'rollup';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
console.log('__dirname:', __dirname);
const dnnThemeSkinPath = 'dnn/Portals/_default/Skins';
const dnnThemeSrcPath = 'src/media';
const srcMediaPath = resolve(__dirname, dnnThemeSrcPath);
console.log('Src Media Path:', srcMediaPath);
const dnnThemeDestPath = 'AccuTheme-Tw4/dist/media';
const destMediaPath = resolve(__dirname, dnnThemeSkinPath, dnnThemeDestPath);
console.log('Dst Media Path:', destMediaPath);
// Run custom script first
import './rollup.config.images.info.js';
// Get source files with absolute paths
const imageFiles = globSync('images/**/*.{png,jpg,jpeg,gif}', {
cwd: srcMediaPath
}).map(file => resolve(srcMediaPath, file));
const svgFiles = globSync('svg/**/*.svg', {
cwd: srcMediaPath
}).map(file => resolve(srcMediaPath, file));
// Debug logging
console.log('Source files:', [...imageFiles, ...svgFiles]);
export default defineConfig({
input: [...imageFiles, ...svgFiles],
plugins: [
image({
dom: false,
include: ['**/*.png', '**/*.jpg', '**/*.jpeg', '**/*.gif', '**/*.svg']
})
],
output: {
dir: destMediaPath,
assetFileNames: (assetInfo) => {
// Parse the original path
const parsedPath = path.parse(assetInfo.name);
// Get the relative path from src/media
const relativePath = assetInfo.name
.replace(/^.*[/\\]src[/\\]media[/\\]/, '')
.replace(/\\/g, '/');
// Extract directory and filename components
const directory = path.dirname(relativePath);
const filename = path.basename(relativePath);
const ext = path.extname(assetInfo.name);
// Debug
console.log('Processing:', {
directory,
filename,
ext
});
// Return path maintaining structure and extension
return directory === '.'
? filename
: `${directory}/${filename}`;
}
}
});