Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dist build for optional packages #8827

Merged
merged 3 commits into from Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -72,6 +72,8 @@ async function main()
packages.forEach((pkg) =>
{
const {
plugin,
pluginExports = true,
bundle,
bundleModule,
version,
Expand Down Expand Up @@ -118,24 +120,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 @@ -146,7 +191,6 @@ async function main()
file,
format: 'iife',
freeze: false,
footer,
sourcemap: true,
},
{
Expand All @@ -168,7 +212,6 @@ async function main()
file: prodName(file),
format: 'iife',
freeze: false,
footer,
sourcemap: true,
},
{
Expand Down