-
Notifications
You must be signed in to change notification settings - Fork 29
/
rollup.config.mjs
92 lines (83 loc) · 3.24 KB
/
rollup.config.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { nodeResolve } from '@rollup/plugin-node-resolve';
import terser from "@rollup/plugin-terser";
import { getBabelOutputPlugin } from '@rollup/plugin-babel';
import sass from 'rollup-plugin-sass';
import autoprefixer from 'autoprefixer';
import cssnano from 'cssnano';
import postcss from 'postcss';
import { existsSync } from 'fs';
import { mkdir, writeFile } from 'fs/promises';
import { dirname } from 'path';
const Elements = [
'alert',
'collapse',
'dropdown',
'modal',
'tab',
'tip',
];
const buildSettings = async () => {
const finalSettings = [];
Elements.forEach((file) => {
finalSettings.push({
input: `src/js/${file}/${file}.js`,
plugins: [nodeResolve()],
output: [
{ file: `dist/js/joomla-${file}.js`, format: 'esm' },
{ file: `docs/_media/js/joomla-${file}.js`, format: 'esm' },
{ file: `dist/js/joomla-${file}.min.js`, format: 'esm', plugins: [terser()] },
{ file: `docs/_media/js/joomla-${file}.min.js`, format: 'esm', plugins: [terser()] },
],
});
finalSettings.push({
input: `src/js/${file}/${file}.js`,
plugins: [nodeResolve(), getBabelOutputPlugin({ presets: ['@babel/preset-env'] })],
output: [
{ file: `dist/js/joomla-${file}-es5.js`, format: 'esm' },
{ file: `docs/_media/js/joomla-${file}-es5.js`, format: 'esm' },
{ file: `dist/js/joomla-${file}-es5.min.js`, format: 'esm', plugins: [getBabelOutputPlugin({ presets: ['@babel/preset-env'] }), terser()] },
{ file: `docs/_media/js/joomla-${file}-es5.min.js`, format: 'esm', plugins: [getBabelOutputPlugin({ presets: ['@babel/preset-env'] }), terser()] },
],
});
});
Elements.forEach((scssFile) => {
finalSettings.push({
input: `src/scss/${scssFile}/${scssFile}.scss`,
plugins: [
sass({
output: false,
processor: css => postcss([autoprefixer])
.process(css)
.then(async (result) => {
const path1 = `dist/css/joomla-${scssFile}.css`;
const path2 = `docs/_media/css/joomla-${scssFile}.css`;
if (!existsSync(dirname(path1))) {
await mkdir(dirname(path1), {recursive: true})
}
await writeFile(path1, result.css, {encoding: 'utf8'});
if (!existsSync(dirname(path2))) {
await mkdir(dirname(path2), {recursive: true})
}
await writeFile(path2, result.css, {encoding: 'utf8'});
postcss([autoprefixer, cssnano])
.process(result.css)
.then(async (result) => {
const path1 = `dist/css/joomla-${scssFile}.min.css`;
const path2 = `docs/_media/css/joomla-${scssFile}.min.css`;
if (!existsSync(dirname(path1))) {
await mkdir(dirname(path1), {recursive: true})
}
await writeFile(path1, result.css, {encoding: 'utf8'});
if (!existsSync(dirname(path2))) {
await mkdir(dirname(path2), {recursive: true})
}
await writeFile(path2, result.css, {encoding: 'utf8'});
});
})
}),
],
});
})
return finalSettings;
};
export default buildSettings();