Skip to content

Commit

Permalink
Add browser builds for optional packages (#8827)
Browse files Browse the repository at this point in the history
  • Loading branch information
bigtimebuddy committed Dec 12, 2022
1 parent 0a35f2c commit 27618a8
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -31,7 +31,7 @@
"watch": "rollup -cw",
"dist": "run-s lint types build build:types docs",
"dist-validate": "workspaces-run --only=\"@pixi/node\" -- npm test",
"postdist": "copyfiles -f bundles/*/dist/* dist",
"postdist": "copyfiles -f bundles/*/dist/* dist && copyfiles -f packages/*/dist/* dist/packages",
"prerelease": "run-s clean:build test",
"postversion": "run-s lint types build build:types",
"release": "lerna version --exact --force-publish",
Expand Down
2 changes: 2 additions & 0 deletions packages/basis/package.json
Expand Up @@ -14,6 +14,7 @@
"main": "lib/index.js",
"module": "lib/index.mjs",
"types": "lib/index.d.ts",
"plugin": "dist/basis.js",
"exports": {
".": {
"import": {
Expand All @@ -30,6 +31,7 @@
"access": "public"
},
"files": [
"dist",
"lib",
"assets",
"*.d.ts"
Expand Down
3 changes: 3 additions & 0 deletions packages/graphics-extras/package.json
Expand Up @@ -4,6 +4,8 @@
"main": "lib/index.js",
"module": "lib/index.mjs",
"types": "lib/index.d.ts",
"plugin": "dist/graphics-extras.js",
"pluginExports": false,
"exports": {
".": {
"import": {
Expand All @@ -29,6 +31,7 @@
"access": "public"
},
"files": [
"dist",
"lib",
"*.d.ts"
],
Expand Down
2 changes: 2 additions & 0 deletions packages/math-extras/package.json
Expand Up @@ -4,6 +4,7 @@
"main": "lib/index.js",
"module": "lib/index.mjs",
"types": "lib/index.d.ts",
"plugin": "dist/math-extras.js",
"exports": {
".": {
"import": {
Expand Down Expand Up @@ -33,6 +34,7 @@
"access": "public"
},
"files": [
"dist",
"lib",
"*.d.ts"
],
Expand Down
2 changes: 2 additions & 0 deletions packages/unsafe-eval/package.json
Expand Up @@ -4,6 +4,7 @@
"main": "lib/index.js",
"module": "lib/index.mjs",
"types": "lib/index.d.ts",
"plugin": "dist/unsafe-eval.js",
"exports": {
".": {
"import": {
Expand All @@ -30,6 +31,7 @@
"access": "public"
},
"files": [
"dist",
"lib",
"*.d.ts"
],
Expand Down
69 changes: 56 additions & 13 deletions rollup.config.js
Expand Up @@ -74,6 +74,8 @@ async function main()
packages.forEach((pkg) =>
{
const {
plugin,
pluginExports = true,
bundle,
bundleModule,
version,
Expand Down Expand Up @@ -120,24 +122,67 @@ async function main()
plugins,
});

const banner = [
`/*!`,
` * ${pkg.name} - v${version}`,
` * Compiled ${(new Date()).toUTCString().replace(/GMT/g, 'UTC')}`,
` *`,
` * ${pkg.name} is licensed under the MIT License.`,
` * http://www.opensource.org/licenses/mit-license`,
` */`,
].join('\n');

// There are a handful of optional packages that are not included in the bundle
// but we still want to build a browser-based version of them, like we would
// for any external plugin.
if (plugin)
{
const name = pkg.name.replace(/[^a-z]+/g, '_');
const file = path.join(basePath, plugin);
const footer = pluginExports ? `Object.assign(this.PIXI, ${name});` : '';
const nsBanner = pluginExports ? `${banner}\nthis.PIXI = this.PIXI || {};`: banner;
const globals = external.reduce((obj, name) => ({ ...obj, [name]: 'PIXI' }), {});

results.push({
input,
output: {
name,
banner: nsBanner,
footer,
file,
format: 'iife',
freeze: false,
sourcemap: true,
globals,
},
treeshake: false,
external,
plugins: bundlePlugins,
}, {
input,
output: {
name,
banner: nsBanner,
footer,
file: prodName(file),
format: 'iife',
freeze: false,
sourcemap: true,
globals,
},
treeshake: false,
external,
plugins: bundlePluginsProd,
});
}

// The package.json file has a bundle field
// we'll use this to generate the bundle file
// this will package all dependencies
if (bundle)
{
const banner = [
`/*!`,
` * ${pkg.name} - v${version}`,
` * Compiled ${(new Date()).toUTCString().replace(/GMT/g, 'UTC')}`,
` *`,
` * ${pkg.name} is licensed under the MIT License.`,
` * http://www.opensource.org/licenses/mit-license`,
` */`,
].join('\n');
const input = path.join(basePath, 'src/index.ts');
const file = path.join(basePath, bundle);
const moduleFile = bundleModule ? path.join(basePath, bundleModule) : '';
let footer;

results.push({
input,
Expand All @@ -148,7 +193,6 @@ async function main()
file,
format: 'iife',
freeze: false,
footer,
sourcemap: true,
},
{
Expand All @@ -170,7 +214,6 @@ async function main()
file: prodName(file),
format: 'iife',
freeze: false,
footer,
sourcemap: true,
},
{
Expand Down

0 comments on commit 27618a8

Please sign in to comment.