-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrollup.config.js
More file actions
76 lines (71 loc) · 1.98 KB
/
rollup.config.js
File metadata and controls
76 lines (71 loc) · 1.98 KB
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
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from '@rollup/plugin-typescript';
import terser from '@rollup/plugin-terser';
const commonInput = { input: 'src/index.ts' };
const playground = {
...commonInput, // Entry point for the playground
output: {
file: 'playground/sense.js', // Output bundled file
format: 'iife', // Self-invoking function for browsers
name: 'SenseOS', // Expose the library as a global variable named "Sense"
},
plugins: [resolve(), commonjs(), typescript()]
};
const dist = [
// NPM Builds (CommonJS and ES Module)
{
...commonInput, // Entry point
output: [
{
file: 'dist/sense.cjs.js',
format: 'cjs', // CommonJS format for Node.js
globals: {
tslib: 'tslib', // Map tslib to a global variable
},
},
{
file: 'dist/sense.esm.js',
format: 'esm', // ES Module format for modern bundlers
globals: {
tslib: 'tslib', // Map tslib to a global variable
},
},
{
file: 'dist/sense.js',
format: 'iife', // IIFE format for browsers
name: 'SenseOS', // Global variable name for the browser
globals: {
tslib: 'tslib', // Map tslib to a global variable
},
},
],
plugins: [resolve(), commonjs(), typescript()],
external: ['tslib'], // Exclude tslib from the bundle for NPM
},
// Browser Build (IIFE for CDN)
{
...commonInput, // Entry point
output: {
file: 'dist/sense.min.js',
format: 'iife', // Self-invoking function for browsers
name: 'SenseOS', // Global variable name for the browser
globals: {
tslib: 'tslib', // Map tslib to a global variable
},
},
external: ['tslib'], // Mark tslib as an external dependency
plugins: [resolve(), commonjs(), typescript(), terser()],
}
]
const buildType = process.env.BUILD;
export default (() => {
switch (buildType) {
case 'dist':
return dist;
case 'playground':
return playground;
default:
return [dist, playground];
}
})();