-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrollup.config.js
132 lines (117 loc) · 3.6 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
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
import { babel } from '@rollup/plugin-babel';
import cleanup from 'rollup-plugin-cleanup';
import terser from '@rollup/plugin-terser';
import pug from './rollup-plugins/rollup-plugin-pug.js';
import sass from './rollup-plugins/rollup-plugin-sass.js';
import del from 'rollup-plugin-del'
import copy from 'rollup-plugin-copy'
import { readFileSync, promises as fs } from 'fs';
import path from 'path';
///import pkg from './package.json' assert { type: 'json' };
///-> Importing JSON modules is an experimental feature and might change at any time
const pkg = JSON.parse(readFileSync('./package.json'));
const isProduction = process.env.BUILD === 'production';
const delTargets = [
"dist/*",
"docs/_resources/dist",
"docs/_data/package.json",
];
const copyTargets = [
{ src: "package.json", dest: "docs/_data/" },
{ src: "dist/*", dest: "docs/_resources/dist" },
];
const computed_plugin = ()=>({
name: 'computed_plugin',
async writeBundle() {
const filePath = path.resolve('dist', 'SmarkForm.esm.js');
try {
const stats = await fs.stat(filePath);
const bundleSizeKB = Math.round(stats.size / 1024);
const lastUpdated = (new Date()).toDateString();
const fileContents = JSON.stringify({
bundleSizeKB,
lastUpdated,
});
// Write the file size to another file
const outputFilePath = path.resolve('docs/_data', 'computed.json');
await fs.writeFile(outputFilePath, fileContents);
} catch (error) {
console.error(`compute_plugin: Error generating computed data: ${error.message}`);
}
},
});
export default [
{
input: 'src/main.js',
output: [
{ // ES module
file: pkg.browser,
format: 'es',
compact: true,
sourcemap: true,
},
{ // UMD module
name: 'SmarkForm',
file: pkg.umd,
format: 'umd',
compact: true,
sourcemap: true,
},
],
plugins: [
del({
targets: delTargets,
runOnce: true,
}),
babel({
babelHelpers: 'bundled',
presets: [
['@babel/preset-env', {
//useBuiltIns: "usage",
// targets: {
// esmodules: true,
// },
}],
],
plugins: [
["@babel/plugin-proposal-decorators", { "version": "2023-01" }]
]
}),
cleanup(),
terser({
compress: {
// Fix terser bug removing actually used assignment:
unused: false,
},
}),
copy({
targets: copyTargets,
copyOnce: true,
}),
]
},
{
input: 'src/examples/index.js',
output: {
file: 'tmp/index.js',
},
plugins: [
computed_plugin(),
sass({
outputStyle: "expanded",
outputDir: "dist/examples",
}),
pug({
pretty: true,
outputDir: "dist/examples",
locals: {
isProduction,
pkg,
},
}),
copy({
targets: copyTargets,
}),
],
},
];