npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

es6-module-transpiler-dist-formatter

v0.0.2

Published

ES6 Module Transpiler Extension to Output Dist Bundle Format.

Downloads

6

Readme

es6-module-transpiler-dist-formatter

NPM version Build Status Coverage Status dependency Status

ES6 Module Transpiler Extension to Output Dist Bundle Format.

Usage

Build tools

Since this formatters is an plugin for [es6-module-transpiler], you can use it with any existing build tool that supports [es6-module-transpiler] as the underlaying engine to transpile the ES6 modules.

You just need to make sure that es6-module-transpiler-dist-formatter is accessible for those tools, and pass the proper formatter option thru the [es6-module-transpiler][] configuration.

Executable

If you plan to use the compile-module CLI, the formatters can be used directly from the command line:

$ npm install es6-module-transpiler
$ npm install es6-module-transpiler-dist-formatter
$ ./node_modules/.bin/compile-modules convert -f es6-module-transpiler-dist-formatter path/to/**/*.js -o build/

The -f option allow you to specify the path to the specific formatter, which is this case is an installed module called es6-module-transpiler-dist-formatter.

Library

You can also use the formatter with the transpiler as a library:

var transpiler = require('es6-module-transpiler');
var DistFormatter = require('es6-module-transpiler-dist-formatter');
var Container = transpiler.Container;
var FileResolver = transpiler.FileResolver;

var container = new Container({
  resolvers: [new FileResolver(['lib/'])],
  formatter: new DistFormatter({ name: 'module-name' })
});

container.getModule('index');
container.write('out/mylib.js');

Supported ES6 Module Syntax

Again, this syntax is in flux and is closely tracking the module work being done by TC39. This package relies on the syntax supported by [es6-module-transpiler], which relies on esprima, you can have more information about the supported syntax here: https://github.com/square/es6-module-transpiler#supported-es6-module-syntax

Compiled Output

First of all, the output format for define() might looks alien even for many developers, but considering that [es6-module-transpiler] relies on Recast to mutate the original ES6 code, it can output the corresponding sourceMap, you should be able to debug the module code without having to understand the actual output format.

Default export

For a module without imports, and a single default exports:

export default function (a, b) {
    return a + b;
}

will produce something like this:

(function() {
    "use strict";
    var index$$default = function (a, b) {
        return a + b;
    };
    var defineAsGlobal = true;

    // Node.js
    if (typeof exports === 'object') {
        module.exports = index$$default;
        defineAsGlobal = false;
    }

    // YModules
    if (typeof modules === 'object') {
        modules.define('module-name', function (provide) {
            provide(index$$default);
        });
        defineAsGlobal = false;
    }

    defineAsGlobal && (global.moduleName = index$$default);
}).call(this);