-
Notifications
You must be signed in to change notification settings - Fork 444
/
rollup.default.config.js
111 lines (80 loc) · 1.94 KB
/
rollup.default.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
/**
* @author syt123450 / https://github.com/syt123450
* @author botime / https://github.com/botime
*/
import { terser } from 'rollup-plugin-terser';
import commonjs from 'rollup-plugin-commonjs';
import nodeResolve from 'rollup-plugin-node-resolve';
const terserOptions = {
output: {
ecma: 5,
preamble: '// https://github.com/tensorspace-team/tensorspace/blob/master/LICENSE'
}
};
const defaultConfig = ( outputDir, createSourceMap = true ) => {
let devExternal = [ 'three', '@tweenjs/tween.js', '@tensorflow/tfjs' ];
let devInput = 'src/tensorspace.dev.js';
let external = [ 'three', '@tweenjs/tween.js', '@tensorflow/tfjs', 'three-trackballcontrols', 'stats-js' ];
let input = 'src/tensorspace.js';
let globals = {
'three': 'THREE',
'@tweenjs/tween.js': 'TWEEN',
'@tensorflow/tfjs': 'tf',
'tensorspace': 'TSP',
'stats-js': 'Stats',
'three-trackballcontrols': 'THREE.TrackballControls'
};
let moduleName = 'TSP';
let config = [
{
external: external,
input: input,
plugins: [ terser( terserOptions ) ],
output: [ {
// Build for browser, minified version
globals: globals,
format: 'iife',
file: `${outputDir}/tensorspace.min.js`,
name: moduleName,
sourcemap: createSourceMap
} ]
},
{
external: external,
input: input,
output: [ {
// Build for browser
globals: globals,
format: 'iife',
file: `${outputDir}/tensorspace.js`,
name: moduleName,
sourcemap: createSourceMap
}, {
// Build for node.js
format: 'cjs',
file: `${outputDir}/tensorspace.cjs.js`,
name: moduleName
} ]
},
{
external: devExternal,
input: devInput,
plugins: [
nodeResolve({
jsnext: true,
main: true,
browser: true,
}),
commonjs(),
],
output: {
// Build for dev
format: 'esm',
file: `${outputDir}/tensorspace.dev.esm.js`,
name: moduleName
}
}
];
return config;
};
export { defaultConfig };