-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathrollup.config.mjs
100 lines (91 loc) · 2.4 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
import copier from 'rollup-plugin-copier';
import cssdiscard from 'postcss-discard-comments';
import cssimport from 'postcss-import';
import cssprefixer from 'autoprefixer';
import cssurl from 'postcss-url';
import path from 'path';
import postcss from 'rollup-plugin-postcss';
import typescript from '@rollup/plugin-typescript';
import terser from '@rollup/plugin-terser';
import { fileURLToPath } from 'url';
const DEVELOP = [
'dev', 'devel', 'development'
].includes(process.env.BUILD);
const F_NAME = fileURLToPath(import.meta.url);
const D_NAME = path.dirname(F_NAME);
const NODE_M = path.normalize(path.join(
D_NAME, 'node_modules',
));
const SOURCES = path.normalize(path.join(
D_NAME, '_assets',
));
const ASSETS = path.normalize(path.join(
D_NAME, 'assets',
));
const STATIC = path.normalize(path.join(
D_NAME, 'static',
));
const assetStyle = {
input: path.join(SOURCES, '_style.css'),
output: {
file: path.join(ASSETS, 'style.css'),
format: 'system',
},
plugins: [
postcss({
plugins: [
cssimport(),
cssurl({
url: 'copy',
assetsPath: path.join(STATIC, 'assets', 'fonts'),
useHash: true,
}),
cssurl({
url: (asset) => path.relative(
STATIC, path.join(NODE_M, asset.url)
),
}),
cssprefixer(),
cssdiscard({
removeAll: true,
}),
],
extract: true,
minimize: !DEVELOP,
sourceMap: (DEVELOP ? 'inline' : false),
}),
copier({
items: [{
src: path.join(NODE_M, 'purecss', 'LICENSE'),
dest: path.join(STATIC, 'assets', 'license-purecss'),
}, {
src: path.join(NODE_M, 'source-code-pro', 'LICENSE.md'),
dest: path.join(STATIC, 'assets', 'license-source-code-pro.md'),
}, {
src: path.join(NODE_M, 'source-sans', 'LICENSE.md'),
dest: path.join(STATIC, 'assets', 'license-source-sans-pro.md'),
}, {
src: path.join(NODE_M, 'source-serif', 'LICENSE.md'),
dest: path.join(STATIC, 'assets', 'license-source-serif-pro.md'),
}],
}),
],
};
const assetScript = {
input: path.join(SOURCES, '_script.ts'),
output: {
file: path.join(ASSETS, 'script.js'),
format: 'iife',
sourcemap: DEVELOP,
},
plugins: [
typescript({
sourceMap: DEVELOP,
}),
(DEVELOP ? null : terser()),
],
};
export default [
assetStyle,
assetScript,
];