-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.js
147 lines (137 loc) · 3.42 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
const nodeResolve = require('@rollup/plugin-node-resolve')
const commonjs = require('@rollup/plugin-commonjs')
const babel = require('@rollup/plugin-babel')
const replace = require('@rollup/plugin-replace')
const terser = require('@rollup/plugin-terser')
const license = require('rollup-plugin-license')
const path = require('path')
const typescript = require('@rollup/plugin-typescript')
const dts = require('rollup-plugin-dts').dts
const VERSION = process.env.VERSION || 'snapshot' // default snapshot
const NODE_ENV = process.env.NODE_ENV === 'production' ? 'production' : 'development' // default development
const dependencies = Object.keys(require('./package.json').dependencies)
dependencies.splice(dependencies.indexOf('lit'), 1)
const input = './src/index.ts'
const name = 'Grapholscape'
const envVariables = {
'process.env.VERSION': JSON.stringify(VERSION),
'process.env.NODE_ENV': JSON.stringify(NODE_ENV),
'preventAssignment': true,
}
const getBabelOptions = () => ({
include: [
'src/**',
'node_modules/lit/**',
'node_modules/@material/**'
],
babelrc: false,
babelHelpers: 'bundled',
presets: [
[
'@babel/preset-env',
{
useBuiltIns: 'usage',
corejs: "3"
}
]
]
})
const typescriptOptions = {
"allowSyntheticDefaultImports": true,
"target": "ES6",
}
const licenseHeaderOptions = {
sourcemap: true,
banner: {
content: {
file: path.join(__dirname, 'LICENSE')
}
}
}
const configs = [
{ // development
input,
output: [
{
file: 'demo/js/grapholscape.js',
format: 'iife',
name,
sourcemap: 'inline',
inlineDynamicImports: true,
},
{
file: 'dist/grapholscape.esm.js',
format: 'es',
name,
sourcemap: 'inline',
inlineDynamicImports: true,
},
],
plugins: [
nodeResolve(),
replace(envVariables),
commonjs({ include: '**/node_modules/**' }),
typescript(typescriptOptions),
],
},
{ // production transpiled, minified
input,
output: [
{
file: 'dist/grapholscape.min.js',
format: 'iife',
inlineDynamicImports: true,
name,
sourcemap: false
},
{
file: 'dist/grapholscape.esm.min.js',
format: 'es',
inlineDynamicImports: true,
sourcemap: false
},
{
file: 'demo/js/grapholscape.js',
format: 'iife',
inlineDynamicImports: true,
name,
sourcemap: false
},
],
plugins: [
nodeResolve(),
replace(envVariables),
commonjs({ include: '**/node_modules/**' }),
typescript(typescriptOptions),
babel(getBabelOptions()),
terser(),
license(licenseHeaderOptions)
]
},
{
input,
output: {
file: 'dist/grapholscape.esm.js',
inlineDynamicImports: true,
format: 'es',
},
plugins: [
nodeResolve(),
replace(envVariables),
commonjs({ include: '**/node_modules/**' }),
typescript(typescriptOptions),
license(licenseHeaderOptions)
],
external: dependencies
}
]
const typesRollup = {
input: "temp/types/src/index.d.ts",
output: [{ file: "dist/index.d.ts", format: "es" }],
plugins: [dts()],
}
// splice(1) removes everything starting at index 1 and returns what he removed
module.exports = {
default: NODE_ENV === 'production'
? [...configs.splice(1), typesRollup] : configs[0]
}