1 Star 0 Fork 0

gileyang/pixijs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
rollup.config.js 7.23 KB
一键复制 编辑 原始数据 按行查看 历史
import path from 'path';
import resolve from '@rollup/plugin-node-resolve';
import { string } from 'rollup-plugin-string';
import sourcemaps from 'rollup-plugin-sourcemaps';
import esbuild from 'rollup-plugin-esbuild';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import jscc from 'rollup-plugin-jscc';
import workspacesRun from 'workspaces-run';
import repo from './package.json';
const bundleTarget = 'es2017';
const moduleTarget = 'es2020';
/**
* Convert a development file name to minified.
* @param {string} name
*/
function prodName(name)
{
return name.replace(/\.(m)?js$/, '.min.$1js');
}
/**
* Escapes the `RegExp` special characters.
* @param {string} str
*/
function escapeRegExp(str)
{
return str.replace(/[$()*+.?[\\\]^{|}]/g, '\\$&');
}
/**
* Convert the name of a package to a `RegExp` that matches the package's export names.
* @param {string} packageName
*/
function convertPackageNameToRegExp(packageName)
{
return new RegExp(`^${escapeRegExp(packageName)}(/.+)?$`);
}
async function main()
{
const commonPlugins = [
sourcemaps(),
resolve({
browser: true,
preferBuiltins: false,
}),
commonjs(),
json(),
string({
include: [
'**/*.frag',
'**/*.vert',
],
}),
];
const plugins = [
jscc({ values: { _VERSION: repo.version, _DEBUG: true } }),
esbuild({ target: moduleTarget }),
...commonPlugins
];
const bundlePlugins = [
jscc({ values: { _VERSION: repo.version, _DEBUG: true } }),
esbuild({ target: bundleTarget }),
...commonPlugins
];
const bundlePluginsProd = [
jscc({ values: { _VERSION: repo.version, _DEBUG: false } }),
esbuild({ target: bundleTarget, minify: true }),
...commonPlugins,
];
const results = [];
const packages = [];
// Collect the list of packages
await workspacesRun({ cwd: __dirname, orderByDeps: true }, async (pkg) =>
{
if (!pkg.config.private)
{
packages.push(pkg);
}
});
packages.forEach((pkg) =>
{
const {
plugin,
pluginExports = true,
bundle,
bundleModule,
dependencies = {},
peerDependencies = {},
} = pkg.config;
// Check for bundle folder
const external = Object.keys(dependencies)
.concat(Object.keys(peerDependencies))
.map(convertPackageNameToRegExp);
const basePath = path.relative(__dirname, pkg.dir);
const input = path.join(basePath, 'src/index.ts');
results.push({
input,
output: [
{
dir: path.join(basePath, 'lib'),
entryFileNames: '[name].js',
format: 'cjs',
freeze: false,
sourcemap: true,
preserveModules: true,
preserveModulesRoot: path.join(basePath, 'src'),
exports: 'named',
},
{
dir: path.join(basePath, 'lib'),
entryFileNames: '[name].mjs',
format: 'esm',
freeze: false,
sourcemap: true,
preserveModules: true,
preserveModulesRoot: path.join(basePath, 'src'),
exports: 'named',
},
],
treeshake: false,
external,
plugins,
});
const banner = [
`/*!`,
` * ${pkg.name} - v${repo.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 = Object.keys(peerDependencies).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 file = path.join(basePath, bundle);
const moduleFile = bundleModule ? path.join(basePath, bundleModule) : '';
results.push({
input,
output: [
{
name: 'PIXI',
banner,
file,
format: 'iife',
freeze: false,
sourcemap: true,
},
{
banner,
file: moduleFile,
format: 'esm',
freeze: false,
sourcemap: true,
}
],
treeshake: false,
plugins: bundlePlugins,
}, {
input,
output: [
{
name: 'PIXI',
banner,
file: prodName(file),
format: 'iife',
freeze: false,
sourcemap: true,
},
{
banner,
file: prodName(moduleFile),
format: 'esm',
freeze: false,
sourcemap: true,
}
],
treeshake: false,
plugins: bundlePluginsProd,
});
}
});
return results;
}
export default main();
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/gileyang/pixijs.git
git@gitee.com:gileyang/pixijs.git
gileyang
pixijs
pixijs
Framebuffer-depth-stencil

搜索帮助

0d507c66 1850385 C8b1a773 1850385