-
Notifications
You must be signed in to change notification settings - Fork 216
Expand file tree
/
Copy pathrollup.config.mjs
More file actions
208 lines (191 loc) · 4.52 KB
/
rollup.config.mjs
File metadata and controls
208 lines (191 loc) · 4.52 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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import { nodeResolve } from '@rollup/plugin-node-resolve';
import replace from '@rollup/plugin-replace';
import terser from '@rollup/plugin-terser';
import copy from 'rollup-plugin-copy';
import esbuild from 'rollup-plugin-esbuild';
import serve from 'rollup-plugin-serve';
import CleanCSS from 'clean-css';
import data from './package.json' with { type: 'json' };
const year = new Date().getFullYear();
function getHeader() {
return `/*!
* Jarallax v${data.version} (${data.homepage})
* Copyright ${year} ${data.author}
* Licensed under MIT (https://github.com/nk-o/jarallax/blob/master/LICENSE)
*/`;
}
function getVideoHeader() {
return `/*!
* Video Extension for Jarallax v${data.version} (${data.homepage})
* Copyright ${year} ${data.author}
* Licensed under MIT (https://github.com/nk-o/jarallax/blob/master/LICENSE)
*/
`;
}
function getElementHeader() {
return `/*!
* DEPRECATED Elements Extension for Jarallax. Use lax.js instead https://github.com/alexfoxy/lax.js
*/
`;
}
const pathCore = './src/core.esm.ts';
const pathCoreUmd = './src/core.umd.ts';
const pathExtVideoUmd = './src/ext-video.umd.ts';
const pathExtElementUmd = './src/deprecated/ext-element.umd.ts';
const pathReact = './src/react/index.ts';
const bundles = [
// Core.
{
input: pathCore,
output: {
banner: getHeader(),
file: './dist/jarallax.esm.js',
format: 'esm',
},
},
{
input: pathCore,
output: {
banner: getHeader(),
file: './dist/jarallax.esm.min.js',
format: 'esm',
compact: true,
},
},
{
input: pathCoreUmd,
output: {
banner: getHeader(),
name: 'jarallax',
file: './dist/jarallax.js',
format: 'umd',
},
},
{
input: pathCoreUmd,
output: {
banner: getHeader(),
name: 'jarallax',
file: './dist/jarallax.min.js',
format: 'umd',
compact: true,
},
},
{
input: pathCore,
output: {
banner: getHeader(),
file: './dist/jarallax.cjs',
format: 'cjs',
},
},
// React Entry.
{
input: pathReact,
output: {
banner: getHeader(),
file: './dist/react/index.js',
format: 'esm',
},
external: ['react'],
},
// Video Extension.
{
input: pathExtVideoUmd,
output: {
banner: getVideoHeader(),
name: 'jarallaxVideo',
file: './dist/jarallax-video.js',
format: 'umd',
},
},
{
input: pathExtVideoUmd,
output: {
banner: getVideoHeader(),
name: 'jarallaxVideo',
file: './dist/jarallax-video.min.js',
format: 'umd',
compact: true,
},
},
// Element Extension.
{
input: pathExtElementUmd,
output: {
banner: getElementHeader(),
name: 'jarallaxElement',
file: './dist/jarallax-element.js',
format: 'umd',
},
},
{
input: pathExtElementUmd,
output: {
banner: getElementHeader(),
name: 'jarallaxElement',
file: './dist/jarallax-element.min.js',
format: 'umd',
compact: true,
},
},
];
const isDev = () => process.env.NODE_ENV === 'dev';
const isUMD = (file) => file.includes('jarallax.js') || file.includes('jarallax-video.js');
const isMinEnv = (file) => file.includes('.min.');
const isSpecificEnv = (file) => isMinEnv(file);
const isDebugAlways = (file) => (isDev() || isUMD(file) ? 'true' : 'false');
function createTypeScriptPlugin() {
return esbuild({
sourceMap: true,
target: 'es2020',
tsconfig: './tsconfig.json',
});
}
const configs = bundles.map(({ input: inputPath, output, external = [] }) => ({
input: inputPath,
external,
output,
plugins: [
nodeResolve({
extensions: ['.mjs', '.js', '.json', '.node', '.ts'],
}),
createTypeScriptPlugin(),
replace({
__DEV__: isSpecificEnv(output.file)
? isDebugAlways(output.file)
: 'process.env.NODE_ENV !== "production"',
preventAssignment: true,
}),
output.file.includes('.min.') && terser(),
],
}));
// Copy CSS file to dist.
configs[0].plugins.unshift(
copy({
targets: [{ src: './src/core.css', dest: 'dist', rename: () => 'jarallax.css' }],
})
);
configs[0].plugins.unshift(
copy({
targets: [
{
src: './src/core.css',
dest: 'dist',
rename: () => 'jarallax.min.css',
transform: (contents) => new CleanCSS().minify(contents).styles,
},
],
})
);
// Dev server.
if (isDev()) {
configs[configs.length - 1].plugins.push(
serve({
open: true,
contentBase: ['demo', './'],
port: 3002,
})
);
}
export default configs;