Skip to content

Commit

Permalink
feat: support esm build
Browse files Browse the repository at this point in the history
courtesy -> epoberezkin#105
  • Loading branch information
mohdashraf010897 committed May 9, 2023
1 parent a8e7172 commit 8bcd543
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
17 changes: 12 additions & 5 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@ var doT = require('dot');
doT.templateSettings.strip = false;

var jst = doT.compile(fs.readFileSync('./src/index.jst', 'utf8'));
fs.writeFileSync('./index.js', jst({es6: false}));
fs.writeFileSync('./react.js', jst({es6: false, react: true}));
try { fs.mkdirSync('./es6'); } catch(e) {}
fs.writeFileSync('./es6/index.js', jst({es6: true}));
fs.writeFileSync('./es6/react.js', jst({es6: true, react: true}));
fs.writeFileSync('./index.js', jst({ es6: false }));
fs.writeFileSync('./react.js', jst({ es6: false, react: true }));
try {
fs.mkdirSync('./es6');
} catch (e) {}
fs.writeFileSync('./es6/index.js', jst({ es6: true }));
fs.writeFileSync('./es6/react.js', jst({ es6: true, react: true }));
try {
fs.mkdirSync('./esm');
} catch (e) {}
fs.writeFileSync('./esm/index.js', jst({ es6: true, esm: true }));
fs.writeFileSync('./esm/react.js', jst({ es6: true, esm: true, react: true }));
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "3.1.3",
"description": "Fast deep equal",
"main": "index.js",
"module": "esm/index.js",
"scripts": {
"eslint": "eslint *.js benchmark/*.js spec/*.js",
"build": "node build",
Expand Down Expand Up @@ -55,7 +56,8 @@
"index.d.ts",
"react.js",
"react.d.ts",
"es6/"
"es6/",
"esm/"
],
"types": "index.d.ts"
}
7 changes: 6 additions & 1 deletion src/index.jst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
var envHasBigInt64Array = typeof BigInt64Array !== 'undefined';
{{?}}

{{? it.esm }}
export default function equal(a, b) {
{{?}}
{{? !it.esm }}
module.exports = function equal(a, b) {
{{?}}
if (a === b) return true;

if (a && b && typeof a == 'object' && typeof b == 'object') {
Expand Down Expand Up @@ -76,4 +81,4 @@ module.exports = function equal(a, b) {

// true if both NaN, false otherwise
return a!==a && b!==b;
};
};

0 comments on commit 8bcd543

Please sign in to comment.