Repository navigation
Expand file tree
/
Copy pathrolldown.config.js
More file actions
130 lines (129 loc) · 3.17 KB
/
Copy pathrolldown.config.js
File metadata and controls
130 lines (129 loc) · 3.17 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
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
}
)
];
// Dependencies stay as plain package imports in dist/, so the bundler of
// whoever installs p5 can resolve them. gifenc is bundled on purpose.
const bundledDependencies = ['gifenc'];
const externalDependencies = Object.keys(pkg.dependencies).filter(
dep => !bundledDependencies.includes(dep)
);
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',
strict: true,
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',
strict: true,
name: 'p5',
banner,
minify: true
},
treeshake: {
moduleSideEffects: false
},
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`,
strict: true,
format: 'iife'
},
{
file: `./lib/p5.${module}.min.js`,
format: 'iife',
strict: true,
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: id =>
externalDependencies.some(dep => id === dep || id.startsWith(`${dep}/`)),
plugins
}
]);