-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.js
84 lines (79 loc) · 1.95 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
import path from 'path';
import { fileURLToPath } from 'url';
import resolve from '@rollup/plugin-node-resolve';
import babel from '@rollup/plugin-babel';
import alias from '@rollup/plugin-alias';
import terser from '@rollup/plugin-terser';
import commonjs from '@rollup/plugin-commonjs';
import scss from 'rollup-plugin-scss';
import postcss from 'postcss';
import cssnano from 'cssnano';
import autoprefixer from 'autoprefixer';
import postcssRTLCSS from 'postcss-rtlcss';
import { Mode, Source } from 'postcss-rtlcss/options';
/**
* Define extensions to be resolved via alias.
*
* @since 1.0.0
*/
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const rootDir = path.resolve(__dirname);
const resolveExtensions = resolve({
extensions: ['.mjs', '.js', '.jsx', '.json', '.sass', '.scss']
});
const resolveAlias = alias({
entries: [{
find: 'src',
replacement: path.resolve(rootDir, './public/assets/src/')
}],
resolveExtensions
});
/**
* Prepare global options.
* Holds path & name of source and destination assets.
*
* @since 1.0.0
*/
const assets = {
"js": {
"src": "./public/assets/src/public.js",
"build": "./public/assets/build/public.min.js",
},
"scss": {
"src": "./public/assets/src/scss",
"build": "./public/assets/build/public.min.css",
"buildName": "public.min.css",
},
}
export default [
{
input: assets['js']['src'],
output: {
file: assets['js']['build'],
name: 'js',
format: 'umd', // "umd", "iife", "esm", "cjs"
},
plugins: [
resolve(),
commonjs(),
babel({ presets: ['@babel/preset-env'], babelHelpers: 'bundled' }),
terser(),
scss({
output: assets['scss']['build'],
fileName: assets['scss']['buildName'],
sourceMap: true,
watch: assets['scss']['src'],
processor: async () => postcss([
autoprefixer(),
postcssRTLCSS({
mode: Mode.override,
source: Source.ltr,
}),
cssnano()
])
}),
resolveAlias,
]
}
];