-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathrolldown.config.js
More file actions
116 lines (115 loc) · 2.69 KB
/
Copy pathrolldown.config.js
File metadata and controls
116 lines (115 loc) · 2.69 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
import { defineConfig } from 'rolldown';
import { replacePlugin } from 'rolldown/plugins';
import { string } from 'rollup-plugin-string';
import pkg from './package.json' with { type: 'json' };
import { globSync } from 'glob';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import alias from '@rollup/plugin-alias';
// import { bundleAnalyzerPlugin } from 'rolldown/experimental';
const plugins = [
string({
include: 'src/webgl/shaders/**/*'
}),
replacePlugin(
{
VERSION_WILL_BE_REPLACED_BY_BUILD: pkg.version
},
{
preventAssignment: true
}
)
];
const banner = `/*! p5.js v${pkg.version} ${new Intl.DateTimeFormat('en-US', { month: 'long', day: 'numeric', year: 'numeric' }).format(new Date())} */`;
export default defineConfig([
{
input: 'src/app.js',
output: [
{
file: './lib/p5.js',
format: 'iife',
name: 'p5',
banner
},
{
file: './lib/p5.esm.js',
format: 'esm',
banner
},
{
file: './lib/p5.esm.min.js',
format: 'esm',
banner,
minify: true
}
],
plugins
},
{
input: 'src/app.js',
output: {
file: './lib/p5.min.js',
format: 'iife',
name: 'p5',
banner,
minify: true
},
plugins: [
...plugins,
alias({
entries: [
{ find: './core/friendly_errors', replacement: './core/noop' }
]
}),
replacePlugin({
IS_MINIFIED: true
})
// bundleAnalyzerPlugin({
// format: 'md'
// })
]
},
//// Addon module builds (e.g. WebGPU) ////
...['webgpu'].map(module => ({
input: `src/${module}/index.js`,
output: [
{
file: `./lib/p5.${module}.js`,
format: 'iife'
},
{
file: `./lib/p5.${module}.min.js`,
format: 'iife',
minify: true
},
{
file: `./lib/p5.${module}.esm.js`,
format: 'esm'
}
],
external: ['../core/main'],
plugins
})),
//// ESM source build ////
{
input: Object.fromEntries(
globSync('src/**/*.js').map(file => [
// This removes `src/` as well as the file extension from each
// file, so e.g. src/nested/foo.js becomes nested/foo
path.relative(
'src',
file.slice(0, file.length - path.extname(file).length)
),
// This expands the relative paths to absolute paths, so e.g.
// src/nested/foo becomes /project/src/nested/foo.js
fileURLToPath(new URL(file, import.meta.url))
])
),
output: {
format: 'es',
dir: 'dist'
},
external: /node_modules\/(?!gifenc)/,
plugins
}
]);