From bff6b216c8b8334b72009cbf4440c7174d5f1126 Mon Sep 17 00:00:00 2001 From: Alexander Schlegel Date: Thu, 20 Jan 2022 23:19:38 +0100 Subject: [PATCH] generate esm code addition to cjs --- package.json | 9 ++++++++- tsconfig.json | 8 ++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 2319cb66..fb0b7c1c 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,11 @@ "unpkg": "dist/index.js", "jsdelivr": "dist/index.js", "main": "dist/index.js", + "module": "dist/esm/index.js", + "exports": { + "require": "./dist/index.js", + "import": "./dist/esm/index.js" + }, "types": "dist/index.d.ts", "author": { "name": "Mohan Upadhyay", @@ -22,7 +27,9 @@ "react" ], "scripts": { - "build": "yarn clean && tsc && yarn copy-files", + "build": "yarn clean && yarn build:cjs && yarn build:esm && yarn copy-files", + "build:esm": "tsc --module es6 --outdir ./dist/esm/", + "build:cjs": "tsc --module commonjs --outdir ./dist/", "build:watch": "tsc --watch", "typecheck": "tsc --noEmit --skipLibCheck", "lint": "eslint ./src --ext .js,.jsx,.ts,.tsx", diff --git a/tsconfig.json b/tsconfig.json index 93bdeb60..2aa99105 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,8 +11,8 @@ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ /* Language and Environment */ - "target": "es5", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ - "lib": ["es2017", "es7", "es6", "dom"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ + "target": "es5", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + "lib": ["es2017", "es7", "es6", "dom"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ // "jsx": "preserve", /* Specify what JSX code is generated. */ // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ @@ -24,9 +24,9 @@ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ /* Modules */ - "module": "es6", /* Specify what module code is generated. */ + "module": "commonjs", /* Specify what module code is generated. */ // "rootDir": "./", /* Specify the root folder within your source files. */ - // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ + "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */