You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now, CosmJS produces CommonJS builds. This works well for all versions of Node.js as well as bundlers like Webpack in order to bundle for the web.
As mentioned in https://vuejsdevelopers.com/2019/02/04/vue-es-module-browser-build/ ("What benefit is there of using Vue as an ES module?"), there is little obvious benefit for switching from CommonJS to ESM since the consumers are either node.js apps or bundlers. However, there is hope that ESM helps optimizing bundle size through tree shaking because ESM can better do static analysis on what is used and what is not (https://webpack.js.org/guides/tree-shaking/). In #904 you see that right now web apps include a lot of unused code that is only needed for key storage.
Other libraries use bundlers to bundle ES modules for the web. This is not desired here as we don't have a single entry point and do not want to decide for that user what should be included in such a bundle.
Do we need CommonJS+ESM hybrid builds?
Node.js 12 does not support ESM natively without feature flags. But this version reaches EOL at 2022-04-30.
JSON test vectors cannot be used easily in tests. const bip39Vectors = require("./src/testdata/bip39.json"); works and TS transpiles import bip39Vectors from "./testdata/bip39.json"; to const bip39_json_1 = __importDefault(require("./testdata/bip39.json")). But an untranspiled import bip39Vectors from "./testdata/bip39.json"; output is not working. See https://nodejs.org/api/esm.html#no-json-module-loading and https://nodejs.org/api/esm.html#json-modules. A workaround for tests is:
File extensions must me used. import { EnglishMnemonic } from "./englishmnemonic.js"; must be used for a local file instead of import { EnglishMnemonic } from "./englishmnemonic";. TS will not do this for us.
The text was updated successfully, but these errors were encountered:
webmaster128
changed the title
Compile to ES modules
Compile to ECMAScript Modules (ESM) instead of CommonJS
Jan 23, 2022
Right now, CosmJS produces CommonJS builds. This works well for all versions of Node.js as well as bundlers like Webpack in order to bundle for the web.
As mentioned in https://vuejsdevelopers.com/2019/02/04/vue-es-module-browser-build/ ("What benefit is there of using Vue as an ES module?"), there is little obvious benefit for switching from CommonJS to ESM since the consumers are either node.js apps or bundlers. However, there is hope that ESM helps optimizing bundle size through tree shaking because ESM can better do static analysis on what is used and what is not (https://webpack.js.org/guides/tree-shaking/). In #904 you see that right now web apps include a lot of unused code that is only needed for key storage.
Other libraries use bundlers to bundle ES modules for the web. This is not desired here as we don't have a single entry point and do not want to decide for that user what should be included in such a bundle.
Do we need CommonJS+ESM hybrid builds?
Does this reduce bundle size
Testing
module
jasmine/jasmine-npm#170)const bip39Vectors = require("./src/testdata/bip39.json");
works and TS transpilesimport bip39Vectors from "./testdata/bip39.json";
toconst bip39_json_1 = __importDefault(require("./testdata/bip39.json"))
. But an untranspiledimport bip39Vectors from "./testdata/bip39.json";
output is not working. See https://nodejs.org/api/esm.html#no-json-module-loading and https://nodejs.org/api/esm.html#json-modules. A workaround for tests is:import { EnglishMnemonic } from "./englishmnemonic.js";
must be used for a local file instead ofimport { EnglishMnemonic } from "./englishmnemonic";
. TS will not do this for us.The text was updated successfully, but these errors were encountered: