Git Product home page Git Product logo

goonpack's Introduction

goonpack

A module bundler, like webpack or browserify, except extremely basic

install

npm install goonpack

features

  • ✔️ basic af
  • ✔️ produces readable output
  • ✔️ TypeScript types
  • ✔️ 100% test coverage
  • ✔️ not horribly slow
  • ❌ single entry point
  • ❌ only supports ES modules
  • ❌ only supports very simple imports and exports
  • ❌ JSON imports? Nope.
  • ❌ no filesystem support, do that yourself
  • ❌ source maps? Ahahaha, no.

why would I use this, who is it for?

No sane or reasonable person, you should really use webpack or browserify or whatever.

That aside, sometimes, not often, but sometimes I have a very simple little app with no external dependencies, and I want to bundle it into a single file for the browser or whatever. The output from webpack et al is pretty ugly, and I thought it would be fun to write something that produced a fairly clean and readable output file.

I'm lazy, so I limited the scope very heavily to make it easy to implement.

usage

const { pack } = require( 'goonpack' )
// or import { pack } from 'goonpack'

/*
  yep, no filesystem support, if your modules are on disk, read them into a
  structure like this
*/
const map = {
  "index.js": "import { foo } from './foo'\nconsole.log( foo )",
  "foo/index.js": "export const foo = 'foo'"
}

// just a string with the bundle source
const source = pack( map )

You can also pass escodegen options to pack as the second argument:

const source = pack( map, {
  format: {
    indent: '  '
  },
  semicolons: false
})

This will produce an output script something like this:

// foo/index.js
const __foo_index = (()=>{
  const foo = 'foo'

  return { foo }
})()

// index.js
const { foo } = __foo_index
console.log( foo )

is there an easy way to turn a folder into the map expected by pack?

npm install @mojule/files

const { readPathBufferMap } = require( '@mojule/files' )

const readFolder = async ( path ) => {
  const bufferMap = await readPathBufferMap( path )

  const map = {}

  Object.keys( bufferMap ).forEach( path => {
    if ( !path.endsWith( '.js' ) ) return

    map[ path ] = bufferMap[ path ].toString( 'utf8' )
  } )

  return map
}

support

exports

  • ✔️ export { name1, name2, …, nameN };
  • export { variable1 as name1, variable2 as name2, …, nameN };
  • ️✔️️️ export let name1, name2, …, nameN; // also var, const
  • ✔️ export let name1 = …, name2 = …, …, nameN; // also var, const
  • ✔️ ️export function FunctionName(){...}
  • ✔️ export class ClassName {...}
  • export default expression;
  • export default function (…) { … } // also class, function*
  • export default function name1(…) { … } // also class, function*
  • export { name1 as default, … };
  • export * from …;
  • export { name1, name2, …, nameN } from …;
  • export { import1 as name1, import2 as name2, …, nameN } from …;
  • export { default } from …;

imports

  • import defaultExport from "path";
  • import * as name from "path";
  • ️️️✔️ import { export } from "path";
  • import { export as alias } from "path";
  • ✔️ import { export1 , export2 } from "path";
  • import { export1 , export2 as alias2 , [...] } from "path";
  • import defaultExport, { export [ , [...] ] } from "path";
  • import defaultExport, * as name from "path";
  • import "path";

license

MIT License

Copyright (c) 2018 Nik Coughlin

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

goonpack's People

Contributors

nrkn avatar

Watchers

 avatar  avatar  avatar

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.