-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrollup.config.js
92 lines (85 loc) · 2.41 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
import { resolve } from "path";
import { terser } from "rollup-plugin-terser";
import commonjs from 'rollup-plugin-commonjs';
import glslify from "rollup-plugin-glslify";
import glslifyImport from "glslify-import";
import livereload from "rollup-plugin-livereload";
import nodeResolve from 'rollup-plugin-node-resolve';
import serve from "rollup-plugin-serve";
import typescript from "rollup-plugin-typescript2";
import pkg from "./package.json";
import tsconfig from "./tsconfig.json";
function generateNamedExports(libraryNames) {
return libraryNames.reduce((map, libraryName) => {
map[libraryName] = Object.keys(require(libraryName));
return map;
}, {});
}
function commonPlugins() {
return [
nodeResolve(),
commonjs({
sourceMap: false,
namedExports: generateNamedExports(["gltf-loader-ts"])
}),
glslify({
transform: [glslifyImport]
})
];
}
function libraryBuild() {
return {
input: "src/index.ts",
plugins: [
...commonPlugins(),
typescript({
typescript: require("typescript"),
cacheRoot: resolve(".cache", "rpt2")
}),
terser()
],
output: [{
file: pkg.main,
format: "umd",
name: pkg.name
}, {
file: pkg.module,
format: "es"
}]
};
}
function devBuild() {
return {
input: "examples/index.ts",
plugins: [
...commonPlugins(),
typescript({
typescript: require("typescript"),
cacheRoot: resolve(".cache", "rpt2"),
tsconfigOverride: {
compilerOptions: {
declaration: false,
sourceMap: true
},
include: tsconfig.include.concat(["examples"])
}
}),
serve({
contentBase: ["dist", "static"],
host: "0.0.0.0",
port: 8080
}),
livereload({
watch: ["dist", "static"]
})
],
output: [{
file: "dist/examples.js",
format: "iife",
sourcemap: true
}]
};
}
const DEV = !!process.env.ROLLUP_WATCH;
const build = (DEV) ? devBuild : libraryBuild;
export default build();