-
Notifications
You must be signed in to change notification settings - Fork 47
/
rollup.config.js
84 lines (79 loc) · 2.15 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
import { nodeResolve } from "@rollup/plugin-node-resolve";
import terser from "@rollup/plugin-terser";
import dts from "rollup-plugin-dts";
import typescript from "rollup-plugin-typescript2";
import { bundle } from "./tools/bundle.cjs";
const outro = bundle.outro();
/**
* Get the rollup config based on the arguments
* @param {"esm" | "cjs" | "iife"} format format of the bundle
* @param {string} generatedFileName generated file name
* @param {boolean} minified should it be minified
*/
function getConfigForFormat(format, minified = false) {
return {
file: minified ? `dist/o-spreadsheet.${format}.min.js` : `dist/o-spreadsheet.${format}.js`,
format,
name: "o_spreadsheet",
extend: true,
globals: { "@odoo/owl": "owl" },
outro,
banner: bundle.jsBanner(),
plugins: minified ? [terser()] : [],
};
}
export default (commandLineArgs) => {
let output = [];
let input = "";
let plugins = [nodeResolve()];
let config = {};
if (commandLineArgs.configDev || commandLineArgs.configDist) {
// Only build one version to improve speed
input = "build/js/index.js";
output = [
{
name: "o_spreadsheet",
extend: true,
outro,
banner: bundle.jsBanner(),
globals: { "@odoo/owl": "owl" },
},
];
if (commandLineArgs.configDev) {
output[0].file = `build/o_spreadsheet.dev.js`;
output[0].format = `iife`;
} else {
output[0].file = `build/o_spreadsheet.js`;
output[0].format = `esm`;
}
config = {
input,
external: ["@odoo/owl"],
output,
plugins,
};
} else {
input = "src/index.ts";
output = [
getConfigForFormat("esm"),
getConfigForFormat("cjs"),
getConfigForFormat("iife"),
getConfigForFormat("iife", true),
];
plugins.push(typescript({ useTsconfigDeclarationDir: true }));
config = [
{
input,
external: ["@odoo/owl"],
output,
plugins,
},
{
input: "dist/types/index.d.ts",
output: [{ file: "dist/o-spreadsheet.d.ts", format: "es" }],
plugins: [dts(), nodeResolve()],
},
];
}
return config;
};