-
Notifications
You must be signed in to change notification settings - Fork 31
/
rollup.config.mjs
116 lines (106 loc) · 2.73 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import copy from 'rollup-plugin-copy';
import sass from 'rollup-plugin-sass';
import typescript from '@rollup/plugin-typescript';
import autoprefixer from 'autoprefixer';
import fs from 'fs';
import path from 'path';
import postcss from 'postcss';
import pkg from './package.json' assert { type: 'json' };
const entries = {
index: 'src/plugins/bulma.ts',
scss: 'src/assets/scss'
};
const exits = {
directory: 'dist',
css: 'dist/bulma.css',
esm: `${pkg.module}`,
umd: `${pkg.main}`
};
const commonSassPluginOptions = {
processor: async (css) => {
const { css: processedCss } = await postcss([autoprefixer]).process(css, {
from: undefined
});
return processedCss;
},
options: {
includePaths: ['node_modules']
}
};
const typescriptPluginOptions = {
sourceMap: false,
// skip type checking of declaration files
skipLibCheck:true,
// enabling declaration (.d.ts) emit
declaration: true,
// decouple declaration files from actual transpiled JavaScript files
declarationDir: "dist/types",
// define included files
include: "src/plugins/**",
};
function createDirectoryIfDoesNotExist(filePath) {
const directoryName = path.dirname(filePath);
if (fs.existsSync(directoryName)) {
return true;
}
createDirectoryIfDoesNotExist(directoryName);
fs.mkdirSync(directoryName);
}
function createMinifiedFileName(fileName) {
const fileNameParts = fileName.split('.');
const fileExtIndex = fileNameParts.length - 1;
const minifiedFileName = [
...fileNameParts.slice(0, fileExtIndex),
'min',
fileNameParts[fileExtIndex]
].join('.');
return minifiedFileName;
}
function writeCssFile(fileName, styles) {
createDirectoryIfDoesNotExist(exits.css);
fs.writeFileSync(fileName, styles);
}
export default function () {
const config = [
{
input: entries.index,
external: ['vue', /oruga\/.*/],
output: [
{
format: 'esm',
file: `${exits.esm}`
},
{
format: 'umd',
name: 'OrugaThemeBulma',
file: `${exits.umd}`
}
],
plugins: [
copy({
targets: [{ src: `${entries.scss}`, dest: `${exits.directory}` }]
}),
sass({
...commonSassPluginOptions,
output(styles) {
writeCssFile(`${exits.css}`, styles);
}
}),
sass({
...commonSassPluginOptions,
output(styles) {
writeCssFile(`${createMinifiedFileName(exits.css)}`, styles);
},
...{
options: {
outputStyle: 'compressed',
...commonSassPluginOptions.options
}
}
}),
typescript(typescriptPluginOptions)
]
}
];
return config;
}