GithubHelp home page GithubHelp logo

rolldown-old / old-rolldown Goto Github PK

View Code? Open in Web Editor NEW
73.0 3.0 1.0 93 KB

Modern bundler built on Rollup with couple more features, such as multiple entry points, presets, better configuration experience and more.

License: MIT License

JavaScript 100.00%
rollup bundler modern es2015 es2015-modules modules es6

old-rolldown's Introduction

rolldown NPM version NPM monthly downloads npm total downloads

Modern bundler built on rollup with support for presets and better configuration experience

code climate standard code style linux build status windows build status coverage status dependency status

You might also be interested in always-done.

Table of Contents

(TOC generated by verb using markdown-toc)

Install

Install with npm

$ npm install rolldown --save

or install using yarn

$ yarn add rolldown

Usage

For more use-cases see the tests

const rolldown = require('rolldown')

API

Related

  • always-done: Handle completion and errors with elegance! Support for streams, callbacks, promises, child processes, async/await and sync functions. A drop-in replacement… more | homepage
  • minibase: Minimalist alternative for Base. Build complex APIs with small units called plugins. Works well with most of the already existing… more | homepage
  • try-catch-core: Low-level package to handle completion and errors of sync or asynchronous functions, using once and dezalgo libs. Useful for and… more | homepage

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Please read the contributing guidelines for advice on opening issues, pull requests, and coding standards.
If you need some help and can spent some cash, feel free to contact me at CodeMentor.io too.

In short: If you want to contribute to that project, please follow these things

  1. Please DO NOT edit README.md, CHANGELOG.md and .verb.md files. See "Building docs" section.
  2. Ensure anything is okey by installing the dependencies and run the tests. See "Running tests" section.
  3. Always use npm run commit to commit changes instead of git commit, because it is interactive and user-friendly. It uses commitizen behind the scenes, which follows Conventional Changelog idealogy.
  4. Do NOT bump the version in package.json. For that we use npm run release, which is standard-version and follows Conventional Changelog idealogy.

Thanks a lot! :)

Building docs

Documentation and that readme is generated using verb-generate-readme, which is a verb generator, so you need to install both of them and then run verb command like that

$ npm install verbose/verb#dev verb-generate-readme --global && verb

Please don't edit the README directly. Any changes to the readme must be made in .verb.md.

Running tests

Clone repository and run the following in that cloned directory

$ npm install && npm test

Author

Charlike Mike Reagent

License

Copyright © 2016-2017, Charlike Mike Reagent. Released under the MIT license.


This file was generated by verb-generate-readme, v0.2.3, on January 03, 2017.
Project scaffolded using charlike cli.

old-rolldown's People

Stargazers

Nick Mazuk avatar Paul Leo avatar  avatar Daniel avatar wandergis avatar Kenta Moriuchi avatar uai avatar nlimpid avatar Erlend Bleken avatar  avatar Nima Mohajeri avatar 叶师傅 avatar Inaridiy avatar Favi_ty avatar  avatar hoangitk avatar Julien Calixte avatar Kuqoi avatar Quincy avatar Zakary avatar Pat avatar Jonas Pauthier avatar Ciaran Liedeman avatar Cristopher avatar Fikri Alwan Ramadhan avatar M Haidar Hanif avatar Jack McNicol avatar jabelic avatar Tony Zhou avatar Moheshwar Amarnath Biswas avatar Christoph Werner avatar Matheus Castiglioni avatar Mark Malstrom avatar Logan McAnsh avatar Adnan Karšić avatar Ben avatar Ryuhei Nakano avatar Andrea Trogolo avatar 朱一 avatar Songpol Anannetikul avatar und3fined avatar Red Huang avatar MetaSky avatar Daniel avatar Alberto Mendez avatar Loïc avatar Sam Huynh avatar ushironoko avatar 陈随易 avatar antx avatar Jordan Newland avatar Mykhaylo Ryechkin avatar Rannie Peralta avatar Titouan Mathis avatar Stead08 avatar Iván Tajes Vidal avatar  avatar Johnny (Hao) Jiang avatar Puru Vijay avatar Zander Martineau avatar Nikolaus Schlemm avatar Mike Tobia avatar Charles Nelson avatar Eisi Sig avatar Tobi Schäfer avatar denistsoi avatar Jacob Mischka avatar Huiren Woo avatar Chee Aun avatar Lan Qingyong avatar Jason Miller avatar  avatar Charlike Mike Reagent avatar

Watchers

James Cloos avatar Charlike Mike Reagent avatar LaoWu avatar

Forkers

kuldeepkeshwar

old-rolldown's Issues

more API

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 }) => {})

rolldown 2019

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.