-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathrollup.config.mjs
83 lines (73 loc) · 2.07 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
import esbuild from 'rollup-plugin-esbuild';
import postcss from 'rollup-plugin-postcss';
import url from '@rollup/plugin-url';
import postcssUrl from 'postcss-url';
import copy from 'rollup-plugin-copy';
import minifyHtml from 'rollup-plugin-minify-html-literals';
import { terser } from 'rollup-plugin-terser';
import path from 'path';
export default function createConfig(packageName) {
const output = {
exports: 'named',
name: packageName,
sourcemap: true,
};
const production = !process.env.ROLLUP_WATCH;
const esbuildPlugin = esbuild({
minify: true,
tsconfig: './tsconfig.json',
platform: 'browser',
treeShaking: true,
loaders: {
'.json': 'json',
},
});
const copyPlugin = copy({
targets: [
// Need to copy the files over for usage
{ src: 'src/assets/fonts', dest: 'dist/assets' },
// { src: 'src/sandbox', dest: 'dist' },
],
});
const postcssPlugin = postcss({
minimize: true,
modules: false,
autoModules: true,
extensions: ['.css', '.less'],
use: {
sass: null,
stylus: null,
less: { javascriptEnabled: true },
},
extract: path.resolve('dist/assets/index.css'),
plugins: [
postcssUrl({
url: 'inline', // enable inline assets using base64 encoding
maxSize: 10, // maximum file size to inline (in kilobytes)
fallback: 'copy', // fallback method to use if max size is exceeded
}),
],
});
const urlPlugin = url();
const terserPlugin =
production &&
terser({
compress: {
drop_console: production,
drop_debugger: production,
},
output: { comments: false },
});
return [
{
input: './index.ts',
plugins: [minifyHtml, esbuildPlugin, postcssPlugin, urlPlugin, copyPlugin, terserPlugin],
output: [{ file: './dist/index.js', format: 'es', ...output }],
},
// {
// input: './src/sandbox/index.ts',
// plugins: [esbuildPlugin, urlPlugin, terserPlugin],
// output: [{ file: './src/sandbox/index.js', format: 'es', ...output }],
// },
];
}