Coder Social home page Coder Social logo

minified UMD detection about cjs-module-lexer HOT 3 CLOSED

nodejs avatar nodejs commented on July 30, 2024
minified UMD detection

from cjs-module-lexer.

Comments (3)

guybedford avatar guybedford commented on July 30, 2024 1

If your own library is able to do deeper execution analysis I woudl suggest writing your own Babel plugin though that can handle more edge cases like these in a custom way.

These types of projects are fun anyway :)

from cjs-module-lexer.

guybedford avatar guybedford commented on July 30, 2024

Because the detection of "exports" is entirely static, we won't even detect cases like:

const e = exports;
e.name = 'value';

There is no execution tracing, because the performance requirements are first and foremost here not to slow down production loading scenarios.

If you load unminfied UMD that uses the exports name it will work:

!(function (t, e) {
  'object' == typeof exports && 'undefined' != typeof module
    ? e(
        exports,
      )
    : 'function' == typeof define && define.amd
    ? define([
        'exports',
      ], e)
    : e();
})(this, function (exports, e) {
  'use strict';

  exports.a = 'a';
  exports.b = 'b';
});

will correctly detect the exports.

In cases where it doesn't work, we suggest writing a custom wrapper ES module to create the named exports yourself and then to load that module instead.

And when in doubt, just load the default.

Yes it is far from perfect, but it's something - hope that makes sense.

from cjs-module-lexer.

chengcyber avatar chengcyber commented on July 30, 2024

Thanks for your quick reply and great work on pushing cjs, esm interop, totally understand the perf concern.
I would like to close this issue then.

from cjs-module-lexer.

Related Issues (20)

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.