From d83f6959528442252705e78d1e88ee22978add30 Mon Sep 17 00:00:00 2001 From: synw Date: Sat, 10 Dec 2022 11:38:29 +0100 Subject: [PATCH] Use a bundler to improve the compilation results --- .gitignore | 1 + package.json | 24 ++++++++++++++---------- rollup.config.js | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 rollup.config.js diff --git a/.gitignore b/.gitignore index 96dcf58..9cf5ebe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .DS_Store node_modules lib +dist yarn.lock package-lock.json diff --git a/package.json b/package.json index 4193917..206a687 100644 --- a/package.json +++ b/package.json @@ -1,21 +1,21 @@ { "name": "djangoinstant", - "version": "0.4.0", + "version": "0.5.0", "description": "Client for the django-instant websockets backend", "scripts": { - "build": "tsc", + "build": "rm -f dist/* && rollup -c", "test": "echo \"Error: no test specified\" && exit 1" }, "files": [ - "/lib" + "/dist" ], - "main": "./lib/index.js", - "module": "./lib/index.js", - "types": "./lib/index.d.ts", + "main": "./dist/index.js", + "module": "./dist/index.es.js", + "types": "./dist/index.d.ts", "exports": { ".": { - "import": "./lib/index.js", - "require": "./lib/index.js" + "import": "./dist/index.es.js", + "require": "./dist/index.cjs.min.js" } }, "dependencies": { @@ -23,9 +23,13 @@ }, "devDependencies": { "tslib": "^2.1.0", - "typescript": "^4.2.3" + "typescript": "^4.2.3", + "rollup": "^2.70.0", + "rollup-plugin-terser": "^7.0.2", + "@rollup/plugin-commonjs": "^21.0.2", + "@rollup/plugin-node-resolve": "^13.1.3", + "@rollup/plugin-typescript": "^8.3.1" }, - "prepublish": "tsc", "author": "synw", "license": "MIT", "repository": { diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000..a369c8c --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,36 @@ +import resolve from '@rollup/plugin-node-resolve'; +import commonjs from '@rollup/plugin-commonjs'; +import typescript from '@rollup/plugin-typescript'; +import { terser } from 'rollup-plugin-terser'; + +//const isProduction = !process.env.ROLLUP_WATCH; + +export default { + input: 'src/index.ts', + output: [ + { + file: 'dist/index.cjs.min.js', + format: 'cjs', + plugins: [terser(),] + }, + { + file: 'dist/index.es.js', + format: 'esm' + }, + { + file: 'dist/index.min.js', + format: 'iife', + name: '$instant', + plugins: [terser()] + }], + plugins: [ + typescript(), + resolve({ + jsnext: true, + main: true, + browser: true, + }), + commonjs(), + //isProduction && terser({ format: { comments: false } }), + ], +}; \ No newline at end of file