Coder Social home page Coder Social logo

esbuild-plugin-named-exports's Introduction

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"

esbuild-plugin-named-exports's People

Contributors

forthealllight avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

himanoa

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.