-
Notifications
You must be signed in to change notification settings - Fork 360
/
Copy pathrollup.config.js
101 lines (93 loc) · 2.85 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
import pkg from "./package.json";
import git from "git-rev-sync";
import typescript from "rollup-plugin-typescript2";
import { terser } from "rollup-plugin-terser";
import dts from "rollup-plugin-dts";
let input, output;
const IIFE_FILENAME = "dist/owl.iife.js";
const CJS_FILENAME = "dist/owl.cjs.js";
const ES_FILENAME = "dist/owl.es.js";
if (pkg.module !== ES_FILENAME || pkg.main !== CJS_FILENAME) {
throw new Error("package.json has been modified. Build script should be updated accordingly");
}
const outro = `
__info__.date = '${new Date().toISOString()}';
__info__.hash = '${git.short()}';
__info__.url = 'https://github.com/odoo/owl';
`;
switch (process.argv[4]) {
case "compiler":
(input = "src/compiler/index.ts"),
(output = [getConfigForFormat("cjs", "dist/compiler.js", "")]);
break;
case "runtime":
input = "src/runtime/index.ts";
output = [
getConfigForFormat("esm", addSuffix(ES_FILENAME, "runtime"), outro),
getConfigForFormat("cjs", addSuffix(CJS_FILENAME, "runtime"), outro),
getConfigForFormat("iife", addSuffix(IIFE_FILENAME, "runtime"), outro),
getConfigForFormat("iife", addSuffix(IIFE_FILENAME, "runtime"), outro, true),
];
break;
default:
(input = "src/index.ts"),
(output = [
getConfigForFormat("esm", ES_FILENAME, outro),
getConfigForFormat("cjs", CJS_FILENAME, outro),
getConfigForFormat("iife", IIFE_FILENAME, outro),
getConfigForFormat("iife", IIFE_FILENAME, outro, true),
]);
}
/**
* Generate from a string depicting a path a new path for the minified version.
* @param {string} pkgFileName file name
*/
function addSuffix(pkgFileName, suffix) {
const parts = pkgFileName.split(".");
parts.splice(parts.length - 1, 0, suffix);
return parts.join(".");
}
/**
* Get the rollup config based on the arguments
* @param {string} format format of the bundle
* @param {string} generatedFileName generated file name
* @param {boolean} minified should it be minified
*/
function getConfigForFormat(format, generatedFileName, outro, minified = false) {
return {
file: minified ? addSuffix(generatedFileName, "min") : generatedFileName,
format: format,
name: "owl",
extend: true,
outro: outro,
freeze: false,
plugins: minified ? [terser()] : [],
indent: " ", // indent with 4 spaces
};
}
export default [
{
input,
output,
plugins: [
typescript({
useTsconfigDeclarationDir: true,
}),
],
},
{
input: "src/compiler/standalone/index.ts",
output: [{ file: "dist/compile_templates.mjs", format: "es" }],
external: ["fs", "fs/promises", "path", "jsdom"],
plugins: [
typescript({
useTsconfigDeclarationDir: true,
}),
],
},
{
input: "dist/types/index.d.ts",
output: [{ file: "dist/types/owl.d.ts", format: "es" }],
plugins: [dts()],
},
];