-
-
Notifications
You must be signed in to change notification settings - Fork 508
Expand file tree
/
Copy pathrollup-full.config.mjs
More file actions
157 lines (143 loc) · 3.94 KB
/
Copy pathrollup-full.config.mjs
File metadata and controls
157 lines (143 loc) · 3.94 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import path from 'path';
import { defineConfig } from 'rollup';
import terser from "@rollup/plugin-terser";
import postcssCombineDuplicatedSelectors from 'postcss-combine-duplicated-selectors';
import cssnanoPlugin from 'cssnano';
import postcss from 'postcss';
import eslint from '@rollup/plugin-eslint';
import * as sass from 'sass';
import pkg from './package.json' with { type: "json"};
const srcDir = './src';
const distDir = './dist';
const cssComponentsDir = `${distDir}/css-components`;
const input = `${srcDir}/index.js`;
const productionMode = !process.env.ROLLUP_WATCH;
export const banner = `/*!
* CookieConsent ${pkg.version}
* ${pkg.repository.url}
* Author ${pkg.author}
* Released under the ${pkg.license} License
*/
`;
function scssPlugin(postcssPlugins) {
const cssMap = new Map();
return {
name: 'scss',
transform(code, id) {
if (!/\.(scss|sass)$/.test(id)) return null;
const { css } = sass.compile(id);
cssMap.set(id, css);
return { code: 'export default "";', map: { mappings: '' } };
},
async generateBundle(outputOptions, bundle) {
if (!cssMap.size) return;
const css = [...cssMap.values()].join('\n');
const processed = await postcss(postcssPlugins.filter(Boolean)).process(css, { from: undefined });
const outFile = outputOptions.file;
const fileName = path.basename(outFile);
for (const key of Object.keys(bundle)) {
delete bundle[key];
}
this.emitFile({ type: 'asset', fileName, source: processed.css });
cssMap.clear();
}
};
}
const cssComponents = [
[
'core/_base.scss',
'base.css'
],
[
'core/components/_consent-modal.scss',
'consent-modal.css'
],
[
'core/components/_preferences-modal.scss',
'preferences-modal.css'
],
[
'abstracts/_dark-color-scheme.scss',
'dark-scheme.css'
],
[
'abstracts/_light-color-scheme.scss',
'light-scheme.css'
]
];
const postcssPlugins = [
postcssCombineDuplicatedSelectors(),
productionMode && cssnanoPlugin({
preset: ["default", {
discardComments: {
removeAll: true,
}
}]
})
];
const cssComponentsRollup = cssComponents.map(component => {
const src = `${srcDir}/scss/${component[0]}`;
const dst = `${cssComponentsDir}/${component[1]}`;
return {
input: src,
output: {
file: dst,
},
plugins: scssPlugin(postcssPlugins)
};
});
export const terserPlugin = terser({
toplevel: true,
format: {
quote_style: 1,
comments: /^!/
},
mangle: {
properties: {
regex: /^_/,
reserved: ['__esModule', '_ccRun'],
keep_quoted: true
}
},
compress: {
passes: 3,
pure_funcs: [ 'debug', 'console.log']
}
});
export default defineConfig(
[
{
input: input,
output: [
{
file: pkg.main,
format: 'umd',
name: 'CookieConsent',
banner: banner
},
{
file: pkg.module,
format: "esm",
exports: "named",
banner: banner
}
],
plugins: [
eslint({
fix: true,
include: ['./src/**'],
exclude: ['./src/scss/**']
}),
productionMode && terserPlugin,
]
},
{
input: `${srcDir}/scss/index.scss`,
output: {
file: `${distDir}/cookieconsent.css`,
},
plugins: scssPlugin(postcssPlugins)
},
...cssComponentsRollup
]
);