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

esbuild-plugin-named-exports

v3.0.7

Published

a esbuild plugin to reexport named exports

Downloads

8,508

Readme

esbuild-plugin-named-exports

a esbuild plugion to reexport some named exports

This plugion is used for reexport some named exports.when we change cjs to esm,we can use this plugin

  1. Example we want to change from 'cjs' to 'esm' default in esbuild:

    //a.js
    module.exports.x = 1
    module.exports.y = 2
        
    //index.js
    module.exports = require('./a.js')

after bundle in esbuild, output is:

    //bundle.js
    var require_a = __commonJS((exports, module) => {
      module.exports.x = 1;
      module.exports.y = 2;
    });
    
    var require_test = __commonJS((exports, module) => {
      module.exports = require_a();
    });
    export default require_test();
    

you will see that in the bundle.js, it only has "default", there is not namedExports, "export x" and "export".

  1. my plugin

based on cjs-module-lexer, this plugin can detect all namedExports.

use:

const esbuldNamedExportsPlugin = require('esbuild-plugin-named-exports')
 ...
 
 require('esbuild').build({
entryPoints: ['./test.js'],
    bundle: true,
    outdir: 'bundle',
    format: 'esm',
    target: 'es2017',
    plugins:[esbuldNamedExportsPlugin]   
})

use this plugin, the bundle.js will be:

    //bundle.js
    var require_a = __commonJS((exports, module) => {
      module.exports.x = 1;
      module.exports.y = 2;
    });
    var require_test = __commonJS((exports, module) => {
      module.exports = require_a();
    });
    var import_test = __toModule(require_test());
    var export_default = import_test.default;
    var export_x = import_test.x;
    var export_y = import_test.y;
    export {
      export_default as default,
      export_x as x,
      export_y as y
    };

you will see that is has the reexport namedExports, "export x" & "export y"