-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrollup.config.js
85 lines (80 loc) · 2.67 KB
/
rollup.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
/* eslint-disable no-shadow */
import { nodeResolve } from '@rollup/plugin-node-resolve';
import css from 'rollup-plugin-import-css';
import replace from '@rollup/plugin-replace';
import { terser } from 'rollup-plugin-terser';
import sass from 'rollup-plugin-sass';
import cssnano from 'cssnano';
import postcss from 'postcss';
import { existsSync } from 'fs';
import { mkdir, writeFile } from 'fs/promises';
import { dirname } from 'path';
import autoprefixer from 'autoprefixer';
import pkg from './package.json';
/* Copyright notice */
const banner = `/*! Gifa11y ${pkg.version} | @author Adam Chaboryk © 2021 - ${new Date().getFullYear()} | @license MIT | @contact [email protected] | https://github.com/adamchaboryk/gifa11y */`;
/**
* Reusable function to process SCSS files.
* @param {string} input - Input SCSS file path.
* @param {string} output - Output CSS file path.
* @param {string} outputMin - Output minified CSS file path.
* @returns {Promise<string>} - Empty string.
*/
const processSCSS = async (input, output, outputMin) => {
const result = await postcss([autoprefixer]).process(input, { from: undefined });
const path = `dist/css/${output}`;
const pathMin = `dist/css/${outputMin}`;
if (!existsSync(dirname(path))) {
await mkdir(dirname(path), { recursive: true });
}
await writeFile(path, result.css, { encoding: 'utf8' });
const minifiedResult = await postcss([cssnano]).process(result.css, { from: undefined });
if (!existsSync(dirname(pathMin))) {
await mkdir(dirname(pathMin), { recursive: true });
}
await writeFile(pathMin, minifiedResult.css, { encoding: 'utf8' });
return '';
};
export default [
{
input: 'src/scss/gifa11y.scss',
plugins: [
sass({
output: false,
processor: (css) => processSCSS(css, 'gifa11y.css', 'gifa11y.min.css'),
}),
],
},
// ES6 standalone files
{
input: 'src/js/gifa11y.js',
plugins: [
nodeResolve(),
css(),
replace({
preventAssignment: true,
'process.env.NODE_ENV': JSON.stringify('production'),
}),
],
output: [
{ banner, file: 'dist/js/gifa11y.esm.js', format: 'esm' },
{ banner, file: 'dist/js/gifa11y.esm.min.js', format: 'esm', plugins: [terser()] },
],
},
// UMD standalone files
{
input: 'src/js/gifa11y.js',
plugins: [
nodeResolve(),
css(),
replace({
preventAssignment: true,
'process.env.NODE_ENV': JSON.stringify('production'),
}),
],
output: [
{ banner, file: 'dist/js/gifa11y.umd.js', format: 'umd', name: 'Gifa11y' },
{ banner, file: 'dist/js/gifa11y.umd.min.js', format: 'umd', name: 'Gifa11y', plugins: [terser()] },
],
},
];