1 Star 0 Fork 19

shiliang888/feng3d

forked from feng3d/feng3d 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
rollup.config.js 6.41 KB
一键复制 编辑 原始数据 按行查看 历史
feng 提交于 2021-07-13 13:54 . !10 monorepo
import path from 'path';
import transpile from 'rollup-plugin-buble';
import json from 'rollup-plugin-json';
import resolve from 'rollup-plugin-node-resolve';
import { string } from 'rollup-plugin-string';
import sourcemaps from 'rollup-plugin-sourcemaps';
import typescript from 'rollup-plugin-typescript';
import dts from 'rollup-plugin-dts';
import minimist from 'minimist';
import commonjs from 'rollup-plugin-commonjs';
import replace from 'rollup-plugin-replace';
import { terser } from 'rollup-plugin-terser';
import batchPackages from '@lerna/batch-packages';
import filterPackages from '@lerna/filter-packages';
import { getPackages } from '@lerna/project';
import repo from './lerna.json';
import fs from 'fs';
/**
* Get a list of the non-private sorted packages with Lerna v3
* @see https://github.com/lerna/lerna/issues/1848
* @return {Promise<Package[]>} List of packages
*/
async function getSortedPackages(scope, ignore)
{
const packages = await getPackages(__dirname);
const filtered = filterPackages(
packages,
scope,
ignore,
false
);
return batchPackages(filtered)
.reduce((arr, batch) => arr.concat(batch), []);
}
async function main()
{
const plugins = [
sourcemaps(),
json(),
resolve({
browser: true,
preferBuiltins: false,
}),
commonjs({}),
typescript(),
string({
include: [
'**/*.frag',
'**/*.vert',
],
}),
replace({
__VERSION__: repo.version,
}),
transpile(),
];
const compiled = (new Date()).toUTCString().replace(/GMT/g, 'UTC');
const sourcemap = true;
const results = [];
// Support --scope and --ignore globs if passed in via commandline
const { scope, ignore } = minimist(process.argv.slice(2));
const packages = await getSortedPackages(scope, ignore);
const namespaces = {};
const pkgData = {};
// Create a map of globals to use for bundled packages
packages.forEach((pkg) =>
{
const data = pkg.toJSON();
pkgData[pkg.name] = data;
namespaces[pkg.name] = data.namespace || 'feng3d';
});
packages.forEach((pkg) =>
{
let banner = [
`/*!`,
` * ${pkg.name} - v${pkg.version}`,
` * Compiled ${compiled}`,
` *`,
` * ${pkg.name} is licensed under the MIT License.`,
` * http://www.opensource.org/licenses/mit-license`,
` */`,
].join('\n');
// Check for bundle folder
const external = Object.keys(pkg.dependencies || []);
const basePath = path.relative(__dirname, pkg.location);
const input = path.join(basePath, 'src/index.ts');
const {
main,
module,
bundle,
bundleInput,
bundleOutput,
bundleNoExports,
standalone,
types,
} = pkgData[pkg.name];
const freeze = false;
results.push({
input,
output: [
{
banner,
file: path.join(basePath, main),
format: 'cjs',
freeze,
sourcemap,
},
{
banner,
file: path.join(basePath, module),
format: 'esm',
freeze,
sourcemap,
},
],
external,
plugins,
});
results.push({
input,
external: standalone ? [] : external,
output: [{ file: path.join(basePath, types), format: 'es' }],
plugins: [
json(),
typescript(),
dts(),
],
});
// The package.json file has a bundle field
// we'll use this to generate the bundle file
// this will package all dependencies
if (bundle)
{
let input = path.join(basePath, bundleInput || 'src/index.ts');
// TODO: remove check once all packages have been converted to typescript
if (!fs.existsSync(input))
{
input = path.join(basePath, bundleInput || 'src/index.js');
}
const file = path.join(basePath, bundle);
const external = standalone ? null : Object.keys(namespaces);
const globals = standalone ? null : namespaces;
const ns = namespaces[pkg.name];
const name = pkg.name.replace(/[^a-z0-9]+/g, '_');
let footer;
if (!standalone)
{
if (bundleNoExports !== true)
{
footer = `Object.assign(this.${ns}, ${name});`;
}
if (ns.includes('.'))
{
const base = ns.split('.')[0];
banner += `\nthis.${base} = this.${base} || {};`;
}
banner += `\nthis.${ns} = this.${ns} || {};`;
}
results.push({
input,
external,
output: Object.assign({
banner,
file,
format: 'iife',
freeze,
globals,
name,
footer,
sourcemap,
}, bundleOutput),
treeshake: false,
plugins,
});
if (process.env.NODE_ENV === 'production')
{
results.push({
input,
external,
output: Object.assign({
banner,
file: file.replace(/\.js$/, '.min.js'),
format: 'iife',
freeze,
globals,
name,
footer,
sourcemap,
}, bundleOutput),
treeshake: false,
plugins: [...plugins, terser({
output: {
comments: (node, comment) => comment.line === 1,
},
})],
});
}
}
});
return results;
}
export default main();
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
TypeScript
1
https://gitee.com/shiliang888/feng3d.git
git@gitee.com:shiliang888/feng3d.git
shiliang888
feng3d
feng3d
develop

搜索帮助