Skip to content

Minimal implementation for umd #106

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

Merged
merged 3 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ parser.visit(ast, {

## Usage in the browser

A browser-friendly version is available in `dist/index.iife.js` (along with its sourcemaps file) in the published version.
A browser-friendly version is available in `dist/index.umd.js` (along with its sourcemaps file) in the published version.

If you are using webpack, keep in mind that minimizing your bundle will mangle function names, breaking the parser. To fix this you can just set `optimization.minimize` to `false`.

Expand Down
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = function (config) {
frameworks: ['mocha'],

// list of files / patterns to load in the browser
files: ['dist/index.iife.js', 'browser-test/*.js'],
files: ['dist/index.umd.js', 'browser-test/*.js'],

// list of files / patterns to exclude
exclude: [],
Expand Down
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
"name": "@solidity-parser/parser",
"version": "0.17.0",
"description": "A Solidity parser built from a robust ANTLR 4 grammar",
"main": "dist/index.cjs.js",
"browser": {
"fs": false,
"path": false
},
"main": "./dist/index.cjs.js",
"browser": "./dist/index.umd.js",
"unpkg": "./dist/index.umd.js",
"files": [
"dist/**/*",
"src/**/*"
Expand Down
25 changes: 24 additions & 1 deletion scripts/build-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,29 @@ build({
bundle: true,
sourcemap: true,
format: 'iife',
banner: {
js: `"use strict";
(function universalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["SolidityParser"] = factory();
else
root["SolidityParser"] = factory();
})(
typeof globalThis !== 'undefined' ? globalThis
: typeof global !== 'undefined' ? global
: typeof self !== 'undefined' ? self
: this || {}
, () => {`,
},
globalName: 'SolidityParser',
outfile: path.resolve(__dirname, '../dist/index.iife.js'),
outfile: path.resolve(__dirname, '../dist/index.umd.js'),
footer: {
js: `
return SolidityParser;
});`,
},
}).catch(() => process.exit(1))