This repository has been archived by the owner on Jun 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
157 lines (144 loc) · 3.76 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
148
149
150
151
152
153
154
155
156
157
import nodeResolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import replace from '@rollup/plugin-replace'
import typescript from '@rollup/plugin-typescript'
import { terser } from 'rollup-plugin-terser'
import license from 'rollup-plugin-license'
import path from 'path'
import json from '@rollup/plugin-json'
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-html'), 1)
dependencies.splice(dependencies.indexOf('lit-element'), 1)
dependencies.push('grapholscape')
const input = './src/index.ts'
const name = 'Sparqling'
const envVariables = {
preventAssignment: true,
'process.env.VERSION': JSON.stringify(VERSION),
'process.env.NODE_ENV': JSON.stringify(NODE_ENV)
}
const getJsonOptions = () => ({
// include: 'src/**',
// exclude: [ '**./**' ],
// for tree-shaking, properties will be declared as
// variables, using either `var` or `const`
preferConst: true, // Default: false
// specify indentation for the generated default export —
// defaults to '\t'
indent: ' ',
// ignores indent and generates the smallest code
compact: true, // Default: false
// generate a named export for every property of the JSON object
namedExports: true // Default: true
})
const licenseHeaderOptions = {
sourcemap: true,
banner: {
content: {
file: path.join(__dirname, 'LICENSE')
}
}
}
const build_development = {
input,
output: {
file: 'public/js/sparqling.js',
format: 'iife',
name,
sourcemap: 'inline',
globals: {
grapholscape: 'Grapholscape'
},
},
plugins: [
json(getJsonOptions()),
nodeResolve({ browser: true }),
replace(envVariables),
commonjs({ include: '**/node_modules/**' }),
typescript({
allowSyntheticDefaultImports: true,
target: 'es6'
}),
],
external: ['grapholscape'],
}
const build_production = [
{
input,
output: [
{
file: 'dist/sparqling.min.js',
format: 'iife',
name,
sourcemap: false,
globals:{
grapholscape: 'Grapholscape'
},
},
{
file: 'public/js/sparqling.js',
format: 'iife',
name,
sourcemap: false,
globals:{
grapholscape: 'Grapholscape'
},
}
],
plugins: [
json(getJsonOptions()),
nodeResolve({ browser: true }),
replace(envVariables),
commonjs({ include: '**/node_modules/**' }),
typescript({
allowSyntheticDefaultImports: true,
target: 'es6'
}),
terser(),
license(licenseHeaderOptions)
],
external: ['grapholscape'],
},
{
input,
output: {
file: 'dist/sparqling.esm.js',
format: 'es',
},
plugins: [
json(getJsonOptions()),
nodeResolve({ browser: true }),
replace(envVariables),
commonjs({ include: '**/node_modules/**' }),
typescript({
allowSyntheticDefaultImports: true,
target: 'es6'
}),
license(licenseHeaderOptions)
],
external: dependencies,
},
{
input,
output: {
file: 'dist/sparqling.esm.min.js',
format: 'es',
},
plugins: [
json(getJsonOptions()),
nodeResolve({ browser: true }),
replace(envVariables),
commonjs({ include: '**/node_modules/**' }),
typescript({
allowSyntheticDefaultImports: true,
target: 'es6'
}),
terser(),
license(licenseHeaderOptions)
],
external: dependencies,
}
]
export default NODE_ENV === 'production' ? build_production : build_development