Skip to content

Commit

Permalink
Minor build optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
limzykenneth committed Sep 5, 2024
1 parent 2fee6ef commit 0ee4505
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 57 deletions.
2 changes: 1 addition & 1 deletion preview/global/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}
</style>

<script src="./p5.rollup.js"></script>
<script src="./p5.js"></script>
</head>
<body>
<script src="./sketch.js"></script>
Expand Down
116 changes: 60 additions & 56 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ const plugins = [
json(),
string({
include: 'src/webgl/shaders/**/*'
}),
replace({
values: {
'VERSION_WILL_BE_REPLACED_BY_BUILD': pkg.version
},
preventAssignment: true
})
];
const banner = `/*! p5.js v${pkg.version} ${dayjs().format('MMMM D, YYYY')} */`;
Expand All @@ -26,35 +32,76 @@ const bundleSize = (name, sourcemap) => {
});
};

const modules = ['math'];
const generateModuleBuild = () => {
return modules.map((module) => {
return {
input: `src/${module}/index.js`,
output: [
{
file: `./lib/p5.${module}.js`,
format: 'iife',
plugins: [
bundleSize(`p5.${module}.js`)
]
},
{
file: `./lib/p5.${module}.min.js`,
format: 'iife',
sourcemap: 'hidden',
plugins: [
terser({
compress: {
global_defs: {
IS_MINIFIED: true
}
},
format: {
comments: false
}
}),
bundleSize(`p5.${module}.min.js`)
]
},
{
file: `./lib/p5.${module}.esm.js`,
format: 'esm',
plugins: [
bundleSize(`p5.${module}.esm.js`)
]
}
],
external: ['../core/main'],
plugins: [
...plugins
]
}
});
};

export default [
{
input: 'src/app.js',
output: [
{
file: './lib/p5.rollup.js',
file: './lib/p5.js',
format: 'iife',
name: 'p5',
banner,
plugins: [
bundleSize("p5.js"),
replace({
'VERSION_WILL_BE_REPLACED_BY_BUILD': pkg.version
})
bundleSize('p5.js')
]
},
{
file: './lib/p5.rollup.esm.js',
file: './lib/p5.esm.js',
format: 'esm',
banner,
plugins: [
bundleSize("p5.esm.js"),
replace({
'VERSION_WILL_BE_REPLACED_BY_BUILD': pkg.version
})
bundleSize('p5.esm.js')
]
},
{
file: './lib/p5.rollup.min.js',
file: './lib/p5.min.js',
format: 'iife',
name: 'p5',
banner,
Expand All @@ -70,10 +117,7 @@ export default [
comments: false
}
}),
bundleSize("p5.min.js", true),
replace({
'VERSION_WILL_BE_REPLACED_BY_BUILD': pkg.version
})
bundleSize('p5.min.js', true)
]
}
],
Expand All @@ -87,45 +131,5 @@ export default [
]
},
// NOTE: comment to NOT build standalone math module
{
input: 'src/math/index.js',
output: [
{
file: './lib/p5.math.js',
format: 'iife',
plugins: [
bundleSize("p5.math.js")
]
},
{
file: './lib/p5.math.min.js',
format: 'iife',
sourcemap: 'hidden',
plugins: [
terser({
compress: {
global_defs: {
IS_MINIFIED: true
}
},
format: {
comments: false
}
}),
bundleSize("p5.math.min.js")
]
},
{
file: './lib/p5.math.esm.js',
format: 'esm',
plugins: [
bundleSize("p5.math.esm.js")
]
}
],
external: ['../core/main'],
plugins: [
...plugins
]
}
// ...generateModuleBuild()
];

0 comments on commit 0ee4505

Please sign in to comment.