diff --git a/package.json b/package.json index 261fd9577a..e3a2dae292 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/basis/package.json b/packages/basis/package.json index ed3d491168..a0b031dac9 100644 --- a/packages/basis/package.json +++ b/packages/basis/package.json @@ -14,6 +14,7 @@ "main": "lib/index.js", "module": "lib/index.mjs", "types": "lib/index.d.ts", + "plugin": "dist/basis.js", "exports": { ".": { "import": { @@ -30,6 +31,7 @@ "access": "public" }, "files": [ + "dist", "lib", "assets", "*.d.ts" diff --git a/packages/graphics-extras/package.json b/packages/graphics-extras/package.json index d99b9e097a..be75023082 100644 --- a/packages/graphics-extras/package.json +++ b/packages/graphics-extras/package.json @@ -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": { @@ -29,6 +31,7 @@ "access": "public" }, "files": [ + "dist", "lib", "*.d.ts" ], diff --git a/packages/math-extras/package.json b/packages/math-extras/package.json index b3e2d7e0ff..bd399df06a 100644 --- a/packages/math-extras/package.json +++ b/packages/math-extras/package.json @@ -4,6 +4,7 @@ "main": "lib/index.js", "module": "lib/index.mjs", "types": "lib/index.d.ts", + "plugin": "dist/math-extras.js", "exports": { ".": { "import": { @@ -33,6 +34,7 @@ "access": "public" }, "files": [ + "dist", "lib", "*.d.ts" ], diff --git a/packages/unsafe-eval/package.json b/packages/unsafe-eval/package.json index fda473c3bf..244f249424 100644 --- a/packages/unsafe-eval/package.json +++ b/packages/unsafe-eval/package.json @@ -4,6 +4,7 @@ "main": "lib/index.js", "module": "lib/index.mjs", "types": "lib/index.d.ts", + "plugin": "dist/unsafe-eval.js", "exports": { ".": { "import": { @@ -30,6 +31,7 @@ "access": "public" }, "files": [ + "dist", "lib", "*.d.ts" ], diff --git a/rollup.config.js b/rollup.config.js index 60d5c8a5b2..b19623e301 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -72,6 +72,8 @@ async function main() packages.forEach((pkg) => { const { + plugin, + pluginExports = true, bundle, bundleModule, version, @@ -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, @@ -146,7 +191,6 @@ async function main() file, format: 'iife', freeze: false, - footer, sourcemap: true, }, { @@ -168,7 +212,6 @@ async function main() file: prodName(file), format: 'iife', freeze: false, - footer, sourcemap: true, }, {