diff --git a/.babelrc.js b/.babelrc.js index 6b53630..6ec826d 100644 --- a/.babelrc.js +++ b/.babelrc.js @@ -1,6 +1,11 @@ +// babel-preset-env: `false` means ESM modules, `undefined` means CJS modules +const modules = process.env.BABEL_ESM === 'true' ? false : undefined; + module.exports = { presets: [ - '@babel/preset-env', + ['@babel/preset-env', { + modules + }], '@babel/preset-typescript', ], -}; \ No newline at end of file +}; diff --git a/package.json b/package.json index d6886cd..9bc5a84 100644 --- a/package.json +++ b/package.json @@ -26,8 +26,16 @@ "license": "MIT", "main": "dist/index.js", "types": "dist/index.d.ts", + "module": "dist/index.mjs", + "exports": { + "import": "./dist/index.mjs", + "require": "./dist/index.js" + }, "scripts": { - "build": "babel src --out-dir dist --extensions \".ts\" && tsc --emitDeclarationOnly", + "build:cjs": "babel src --out-dir dist --extensions \".ts\" --out-file-extension .js", + "build:esm": "BABEL_ESM=true babel src --out-dir dist --extensions \".ts\" --out-file-extension .mjs", + "build:tsc": "tsc --emitDeclarationOnly", + "build": "yarn build:cjs && yarn build:esm && yarn build:tsc", "lint": "eslint src --ext .js,.ts", "prepublish": "yarn build", "test": "yarn test-node && yarn test-browser",