-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.mjs
95 lines (79 loc) · 2.03 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
import { defineConfig } from 'rollup';
import { babel } from '@rollup/plugin-babel';
import terser from '@rollup/plugin-terser';
import replace from '@rollup/plugin-replace';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import postcss from 'rollup-plugin-postcss';
import CleanCSS from 'clean-css';
const minifyCSS = () => {
return {
name: 'mbi-minify-css',
version: '1.0.0',
async generateBundle(options, bundle) {
const clean = new CleanCSS({ sourceMap: true });
for (const [filename, data] of Object.entries(bundle)) {
if (!filename.endsWith('.css')) continue;
const output = clean.minify(data.source, {
version: 3,
file: filename,
sources: [],
sourcesContent: [data.source],
mappings: '',
});
data.source = output.styles;
if (output.sourceMap) {
const { sourceMap } = output;
const mapname = filename + '.map';
data.source += `\n/*# sourceMappingURL=${mapname} */`;
this.emitFile({
type: 'asset',
fileName: mapname,
source: sourceMap.toString(),
});
}
}
}
};
};
export default defineConfig({
input: {
mbido: `src/main.js`,
},
output: [
{
dir: 'dist',
entryFileNames: '[name].js',
format: 'iife',
},
{
dir: 'dist',
entryFileNames: '[name].min.js',
format: 'iife',
sourcemap: true,
plugins: [
minifyCSS(),
terser(),
],
},
],
treeshake: true,
plugins: [
postcss({
extract: true,
modules: false,
use: ['sass'],
plugins: [],
}),
resolve(),
commonjs(),
replace({
preventAssignment: true,
'process.env.NODE_ENV': "'production'"
}),
babel({
presets: ['@babel/preset-env'],
babelHelpers: 'bundled'
}),
]
});