rolldown-old / old-rolldown Goto Github PK
View Code? Open in Web Editor NEWModern bundler built on Rollup with couple more features, such as multiple entry points, presets, better configuration experience and more.
License: MIT License
Modern bundler built on Rollup with couple more features, such as multiple entry points, presets, better configuration experience and more.
License: MIT License
const fs = require('fs');
const path = require('path');
const rollup = require('rollup');
const argParser = require('mri');
const commonjs = require('rollup-plugin-commonjs');
const progress = require('rollup-plugin-progress');
const filesize = require('rollup-plugin-filesize');
const resolve = require('rollup-plugin-node-resolve');
const terser = require('rollup-plugin-terser');
const babel = require('rollup-plugin-babel');
const json = require('rollup-plugin-json');
const builtinModules = require('builtin-modules');
function prettierPlugin() {
return {
name: 'rollup-plugin-prettier-bundle',
generateBundle(output) {},
};
}
async function createConfig(input, options) {
const opts = Object.assign({}, options);
const extMap = {
es: '.mjs',
cjs: '.js',
};
const destMap = {
es: 'module',
cjs: 'main',
};
const cwd = process.cwd();
const outDir = (x) => opts.outDir || path.join(cwd, 'dist', destMap[x]);
const outFile = (x) => path.join(outDir(x), `index${extMap[x]}`);
const join = (...x) => path.join(cwd, ...x);
const pkg = require(join('package.json'));
const exts = arrayify(opts.extensions);
const extensions =
exts.length > 0 ? exts : ['.js', '.jsx', '.mjs', '.ts', '.tsx'];
const possibleInputs = [
input,
join('index.js'),
join('src', 'index.js'),
join('src', 'index.mjs'),
join('src', 'index.ts'),
];
// first existing, for now
const [inputFile] = possibleInputs.filter((x) => fs.existsSync(x));
const license = `/** Released under the ${opts.license ||
pkg.license} License. See LICENSE file. */`;
const outMap = {
cjs: {
exports: 'named',
banner: license,
file: outFile('cjs'),
format: 'cjs',
preferConst: true,
// don't break oldschool/classic/normal node.js
outro: 'module.exports = exports.default || exports;',
},
es: {
exports: 'named',
banner: license,
file: outFile('es'),
format: 'es',
preferConst: true,
},
};
outMap.esm = outMap.es;
let formats = arrayify(opts.format)
.reduce((acc, x) => acc.concat(x.indexOf(',') > -1 ? x.split(',') : x), [])
.filter(Boolean);
let output = null;
if (formats.length === 0) {
formats = ['cjs', 'es'];
}
if (formats.length === 1) {
output = outMap[formats[0]];
} else {
output = formats.map((x) => outMap[x]);
}
return {
input: inputFile,
output,
external: builtinModules,
inlineDynamicImports: true,
experimentalTopLevelAwait: true,
plugins: [
progress(),
resolve({
preferBuiltins: true,
module: true,
jsnext: true,
main: true,
}),
json({ preferConst: true }),
babel({
exclude: 'node_modules/**',
externalHelpers: true,
extensions,
}),
commonjs({
extensions,
}),
opts.minify && terser.terser(),
filesize({
showBrotliSize: true,
showGzippedSize: true,
showMinifiedSize: true,
}),
],
};
}
const argv = argParser(process.argv.slice(2), {
alias: {
i: 'input',
d: ['out-dir', 'outdir', 'outDir'],
f: 'format',
m: 'minify',
x: ['ext', 'extensions'],
l: ['license'],
},
});
let ROLLUP_CACHE = null;
createConfig(argv.input || argv._[0], argv)
.then(async (cfg) => {
const bundle = await rollup.rollup(
Object.assign({}, cfg, { cache: ROLLUP_CACHE }),
);
ROLLUP_CACHE = bundle.cache;
arrayify(cfg.output).map(async (outputOptions) => {
await bundle.write(outputOptions);
});
})
.catch(console.error);
function arrayify(val) {
if (!val) return [];
if (Array.isArray(val)) return val;
return [val];
}
run with
node rolldown.js [src/index.js]
by defaults tries index.js
, src/index.js
, src/index.mjs
and src/index.ts
, works with TypeScript out of the box and generates CJS and ESM bundles with bundled deps.
in some places, instead of extend-shallow
Easy to implement? If opts.entry
is object loop over it.
https://github.com/rolldown links to https://rolldown.now.sh/ which redirects to https://rolldown.vercel.app/ which returns 404.
Is there a new site? In particular I'd be interested to see a playground/REPL like Rollup/esbuild have.
when published: tunnckoCore/ideas#46 (comment)
rolldown.transform = (source, options) => {
if (!source) {
// or something like that
// (need more strict check for that param)
return Promise.reject(new TypeError('expect a string'))
}
return utils.tmpFile(source).then((file) => {
options.entry = file.path
delete options['source']
// we don't want to (force to not) write to disk
// but resolve `{ code, map }` object
delete options['targets']
delete options['dest']
return rolldown(options)
})
}
rolldown.plugin = (plugin, options) => {
rolldown.plugins.push([plugin, options])
return rolldown
}
// usage
// { name: 'my-awesome-plugin', transform: (code, id) => {} }
rolldown.plugin(Object)
// e.g. buble
rolldown.plugin(Function)
// e.g. buble, { target: { node: '4' } }
rolldown.plugin(Function, Object)
// e.g. 'buble'
rolldown.plugin(String)
// e.g. 'buble', { target: { node: '4' } }
rolldown.plugin(String, Object)
rolldown.transform('some source code', {
plugins: [
'commonjs',
['node-resolve', { jsnext: true }],
['buble', { target: { node: '4' } }]
]
}).then(({ code, map }) => {})
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.