From e86d43f11f377ae8c6b6c58b0c0efe8ee4b2b270 Mon Sep 17 00:00:00 2001 From: Konstantin Kovalev Date: Thu, 30 May 2019 17:59:39 +0200 Subject: [PATCH] Optimise distributive for ES6 and CJS modules --- .gitignore | 1 + .prettierignore | 1 + package.json | 2 +- rollup.config.js | 8 +++++--- scripts/clean.js | 2 +- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 9f7fefb..0e896cb 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ #distributive files /browser/*.* +/esm/*.* *.js *.mjs *.map diff --git a/.prettierignore b/.prettierignore index e7a262f..0d77754 100644 --- a/.prettierignore +++ b/.prettierignore @@ -2,6 +2,7 @@ node_modules coverage browser +esm *.js *.mjs !rollup.config.js diff --git a/package.json b/package.json index ce4845b..068185c 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.6.5", "description": "The library brings most of the familiar functional techniques (like functional composition) to asynchronous world with shining Promises", "main": "index.js", - "module": "index.mjs", + "module": "esm/index.js", "scripts": { "test": "node -r esm scripts/unitTest.js", "lint": "npx eslint '**/*.js'", diff --git a/rollup.config.js b/rollup.config.js index 03737c4..3963016 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -28,6 +28,7 @@ ${licenseText.replace(/^/gm, " * ")} }; const getSourceFilesList = () => globby(["src/*.js"]); +const getMainFileAsList = () => globby(["src/index.js"]); const getFileName = file => file .split("/") @@ -49,11 +50,11 @@ const config = (format, folder, minified = false) => input => ({ input, output: { file: `${folder ? folder + "/" : ""}${ - format === "umd" ? getUmdOutput(input, minified) : getOutput(input, format === "es" ? "mjs" : "js") + format === "umd" ? getUmdOutput(input, minified) : getOutput(input, "js") }`, format, sourcemap: true, - sourcemapFile: `${folder ? folder + "/" : ""}${getOutput(input, format === "es" ? "mjs" : "js")}.map`, + sourcemapFile: `${folder ? folder + "/" : ""}${getOutput(input, "js")}.map`, strict: true, banner: getActualBanner(), name: format === "umd" ? "funCtional" : undefined @@ -67,10 +68,11 @@ const config = (format, folder, minified = false) => input => ({ }); const sourceFiles = getSourceFilesList(); +const mainFileAsList = getMainFileAsList(); export default [ ...sourceFiles.map(config("cjs")), - ...sourceFiles.map(config("es")), + ...mainFileAsList.map(config("es", "esm")), ...sourceFiles.map(config("umd", "browser")), ...sourceFiles.map(config("umd", "browser", true)) ]; diff --git a/scripts/clean.js b/scripts/clean.js index 51a602d..d93b11c 100644 --- a/scripts/clean.js +++ b/scripts/clean.js @@ -1,7 +1,7 @@ import del from "del"; const clean = async () => - del(["browser", "*.js", "*.mjs", "*.map", "!babel.config.js", "!jest.config.js", "!rollup.config.js"]); + del(["browser", "esm", "*.js", "*.map", "!babel.config.js", "!jest.config.js", "!rollup.config.js"]); // Makes the script crash on unhandled rejections instead of silently // ignoring them. In the future, promise rejections that are not handled will