Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OMIT_MODULE_EXPORTS to omit module code #12952

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -526,3 +526,4 @@ a license to everyone to use it as detailed in LICENSE.)
* Wouter van Oortmerssen <wvo@google.com> (copyright owned by Google, LLC)
* Alexey Sokolov <sokolov@google.com> (copyright owned by Google, LLC)
* Ivan Romanovski <ivan.romanovski@gmail.com>
* Kevin Lubick <kjlubick@google.com> (copyright owned by Google, LLC)
26 changes: 13 additions & 13 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2874,19 +2874,19 @@ def modularize():
with open(final_js, 'w') as f:
f.write(src)

# Export using a UMD style export, or ES6 exports if selected

if shared.Settings.EXPORT_ES6:
f.write('export default %s;' % shared.Settings.EXPORT_NAME)
elif not shared.Settings.MINIMAL_RUNTIME:
f.write('''\
if (typeof exports === 'object' && typeof module === 'object')
module.exports = %(EXPORT_NAME)s;
else if (typeof define === 'function' && define['amd'])
define([], function() { return %(EXPORT_NAME)s; });
else if (typeof exports === 'object')
exports["%(EXPORT_NAME)s"] = %(EXPORT_NAME)s;
''' % {'EXPORT_NAME': shared.Settings.EXPORT_NAME})
if not shard.Settings.OMIT_MODULE_EXPORTS:
kjlubick marked this conversation as resolved.
Show resolved Hide resolved
# Export using a UMD style export, or ES6 exports if selected
if shared.Settings.EXPORT_ES6:
f.write('export default %s;' % shared.Settings.EXPORT_NAME)
elif not shared.Settings.MINIMAL_RUNTIME:
f.write('''\
if (typeof exports === 'object' && typeof module === 'object')
module.exports = %(EXPORT_NAME)s;
else if (typeof define === 'function' && define['amd'])
define([], function() { return %(EXPORT_NAME)s; });
else if (typeof exports === 'object')
exports["%(EXPORT_NAME)s"] = %(EXPORT_NAME)s;
''' % {'EXPORT_NAME': shared.Settings.EXPORT_NAME})

save_intermediate('modularized')

Expand Down
12 changes: 8 additions & 4 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ var STRICT = 0;
// include `_main`.
var IGNORE_MISSING_MAIN = 1;

// Automatically attempt to add archive indexes at link time to archives that
// Automatically attempt to add archive indexes at link time to archives that
// don't already have them. This can happen when GNU ar or GNU ranlib is used
// rather than `llvm-ar` or `emar` since the former don't understand the wasm
// object format.
Expand Down Expand Up @@ -964,7 +964,7 @@ var DETERMINISTIC = 0;
// (If WASM_ASYNC_COMPILATION is off, that is, if compilation is
// *synchronous*, then it would not make sense to return a Promise, and instead
// the Module object itself is returned, which is ready to be used.)
//
//
// The default name of the function is `Module`, but can be changed using the
// `EXPORT_NAME` option. We recommend renaming it to a more typical name for a
// factory function, e.g. `createModule`.
Expand All @@ -973,14 +973,14 @@ var DETERMINISTIC = 0;
// You use the factory function like so:
//
// const module = await EXPORT_NAME();
//
//
// or:
//
// let module;
// EXPORT_NAME().then(instance => {
// module = instance;
// });
//
//
//
// The factory function accepts 1 parameter, an object with default values for
// the module instance:
Expand Down Expand Up @@ -1016,6 +1016,10 @@ var DETERMINISTIC = 0;
// code, allowing better dead code elimination and minification.
var MODULARIZE = 0;

// By default, if MODULARIZE=1, emscripten will output JS to support UMD exports.
// If OMIT_MODULE_EXPORTS=1, this code is omitted.
var OMIT_MODULE_EXPORTS = 0;

// Export using an ES6 Module export rather than a UMD export. MODULARIZE must
// be enabled for ES6 exports.
var EXPORT_ES6 = 0;
Expand Down