From cded25748b987bb7f67523e69d094166f905e221 Mon Sep 17 00:00:00 2001 From: Sergey Sova Date: Mon, 31 May 2021 18:07:20 +0300 Subject: [PATCH] build: add umd build --- .config/eslint-config.json | 3 ++- .gitignore | 5 ++--- .scripts/rollup.js | 34 ---------------------------- package.json | 10 ++++----- rollup.config.js | 45 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 54 insertions(+), 43 deletions(-) delete mode 100644 .scripts/rollup.js create mode 100644 rollup.config.js diff --git a/.config/eslint-config.json b/.config/eslint-config.json index 6cad83b6..943fc165 100644 --- a/.config/eslint-config.json +++ b/.config/eslint-config.json @@ -7,7 +7,8 @@ "**/*.spec.tsx", "**/*.spec.ts", "**/*.spec.js", - "_/**.js" + "_/**.js", + "rollup.config.js" ], "env": { "jest": true }, "rules": { diff --git a/.gitignore b/.gitignore index efcd0327..789896a8 100644 --- a/.gitignore +++ b/.gitignore @@ -123,7 +123,7 @@ typings/ # nuxt.js build output .nuxt -# rollup.js default build output +# rollup.config.js default build output dist/ # Uncomment the public line if your project uses Gatsby @@ -179,6 +179,5 @@ $RECYCLE.BIN/ # End of https://www.gitignore.io/api/node,windows,linux,macos -patronum.cjs.js -patronum.cjs.js.map +dist .idea diff --git a/.scripts/rollup.js b/.scripts/rollup.js deleted file mode 100644 index b455257c..00000000 --- a/.scripts/rollup.js +++ /dev/null @@ -1,34 +0,0 @@ -const path = require('path'); -const { rollup } = require('rollup'); -const { babel } = require('@rollup/plugin-babel'); -const { terser } = require('rollup-plugin-terser'); -const { nodeResolve } = require('@rollup/plugin-node-resolve'); -const commonjs = require('@rollup/plugin-commonjs'); - -const plugins = [ - nodeResolve({ extensions: ['.js'] }), - commonjs({ extensions: ['.js'] }), - terser({}), -]; - -async function main() { - const build = await rollup({ - input: path.resolve(__dirname, '..', 'index.js'), - external: ['effector'], - plugins, - }); - - await build.write({ - file: path.resolve(__dirname, '..', 'patronum.cjs.js'), - format: 'cjs', - freeze: false, - exports: 'named', - sourcemap: true, - externalLiveBindings: false, - }); -} - -main().catch((error) => { - console.error(error); - process.exit(-1); -}); diff --git a/package.json b/package.json index db518b56..7fa5df7e 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,10 @@ { "name": "patronum", - "version": "1.2.0-next.0", + "version": "1.2.0-next.1", "description": "☄️ Effector utility library delivering modularity and convenience", - "main": "patronum.cjs.js", + "main": "dist/patronum.cjs.js", "types": "index.d.ts", + "browser": "dist/patronum.umd.js", "scripts": { "test": "yarn test:code && yarn test:types", "test:code": "jest", @@ -12,7 +13,7 @@ "format": "prettier --write \"./src/**/**.{ts,tsx,js,jsx,json}\"", "lint": "eslint ./", "build:methods": "node ./.scripts/build.js && prettier --config ./.prettierrc --write ./babel-plugin-factories.json", - "build:cjs": "node ./.scripts/rollup.js", + "build:cjs": "rollup -c", "prepublishOnly": "yarn build:methods && yarn build:cjs" }, "files": [ @@ -26,8 +27,7 @@ "library.js", "macro.d.ts", "macro.js", - "patronum.cjs.js.map", - "patronum.cjs.js" + "dist" ], "repository": { "type": "git", diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 00000000..caf16eae --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,45 @@ +const path = require('path'); +const { terser } = require('rollup-plugin-terser'); +const { nodeResolve } = require('@rollup/plugin-node-resolve'); +const commonjs = require('@rollup/plugin-commonjs'); + +const plugins = [ + nodeResolve({ extensions: ['.js'] }), + commonjs({ extensions: ['.js'] }), + terser({}), +]; + +const input = 'index.js'; + +// eslint-disable-next-line import/no-anonymous-default-export +export default [ + { + input, + external: ['effector'], + plugins, + output: { + file: 'patronum.cjs.js', + format: 'cjs', + freeze: false, + exports: 'named', + sourcemap: true, + externalLiveBindings: false, + }, + }, + { + input, + external: ['effector'], + plugins, + output: { + name: 'patronum', + file: 'patronum.umd.js', + format: 'umd', + exports: 'named', + sourcemap: true, + freeze: false, + globals: { + effector: 'effector', + }, + }, + }, +];