From 5ab7beabadaded36b892c1c401783f91390089e8 Mon Sep 17 00:00:00 2001 From: mkosir Date: Sun, 21 Jan 2024 10:47:46 +0100 Subject: [PATCH] fix(deps): update dependencies --- package-lock.json | 4 +- package.json | 16 +++---- rollup.config.ts | 104 ++++++++++++++++++++++++++++++++++++---------- 3 files changed, 91 insertions(+), 33 deletions(-) diff --git a/package-lock.json b/package-lock.json index a58302a3..5eb76f03 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "react-parallax-tilt", - "version": "0.0.0-development", + "version": "0.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "react-parallax-tilt", - "version": "0.0.0-development", + "version": "0.0.0", "license": "MIT", "devDependencies": { "@babel/preset-env": "7.23.8", diff --git a/package.json b/package.json index e5b2473b..a7a9597d 100644 --- a/package.json +++ b/package.json @@ -1,19 +1,19 @@ { "name": "react-parallax-tilt", "description": "Easily apply tilt hover effect on React components - lightweight/zero dependencies", - "version": "0.0.0-development", + "version": "0.0.0", "type": "module", - "main": "./dist/index.js", - "module": "./dist/index.mjs", - "types": "./dist/index.d.ts", + "types": "./dist/legacy/index.d.ts", + "module": "./dist/legacy/index.js", + "main": "./dist/legacy/index.cjs", "exports": { "import": { - "types": "./dist/index.d.ts", - "default": "./dist/index.mjs" + "types": "./dist/modern/index.d.ts", + "default": "./dist/modern/index.js" }, "require": { - "types": "./dist/index.d.ts", - "default": "./dist/index.js" + "types": "./dist/modern/index.d.cts", + "default": "./dist/modern/index.cjs" } }, "files": [ diff --git a/rollup.config.ts b/rollup.config.ts index 838ed559..094e14b6 100644 --- a/rollup.config.ts +++ b/rollup.config.ts @@ -1,45 +1,45 @@ import commonjs from '@rollup/plugin-commonjs'; import terser from '@rollup/plugin-terser'; import typescript from '@rollup/plugin-typescript'; -import { defineConfig } from 'rollup'; +import { defineConfig, RollupOptions } from 'rollup'; import { dts } from 'rollup-plugin-dts'; import packageJson from './package.json' assert { type: 'json' }; import tsConfig from './tsconfigs/tsconfig.base.json' assert { type: 'json' }; -const isProduction = process.env.NODE_ENV === 'production'; +const IS_PRODUCTION = process.env.NODE_ENV === 'production'; -const inputFile = 'src/index.ts'; +const PATH_INPUT_FILE = 'src/index.ts'; +const PATH_TSCONFIG = './tsconfigs/tsconfig.prod.json'; -const rollupConfig = defineConfig([ +const GLOBALS = { + react: 'React', + 'react-dom': 'ReactDOM', +} as const; + +const LEGACY_CONFIG = [ { - input: inputFile, + input: PATH_INPUT_FILE, output: [ + { + file: packageJson.module, + format: 'esm', + sourcemap: !IS_PRODUCTION, + globals: GLOBALS, + }, { file: packageJson.main, name: packageJson.name, format: 'umd', - sourcemap: !isProduction, - globals: { - react: 'React', - 'react-dom': 'ReactDOM', - }, - }, - { - file: packageJson.module, - format: 'esm', - sourcemap: !isProduction, - globals: { - react: 'React', - 'react-dom': 'ReactDOM', - }, + sourcemap: !IS_PRODUCTION, + globals: GLOBALS, }, ], plugins: [ commonjs(), typescript({ - tsconfig: './tsconfigs/tsconfig.prod.json', - sourceMap: !isProduction, + tsconfig: PATH_TSCONFIG, + sourceMap: !IS_PRODUCTION, }), terser({ output: { comments: false }, @@ -56,7 +56,7 @@ const rollupConfig = defineConfig([ ], }, { - input: inputFile, + input: PATH_INPUT_FILE, output: { file: packageJson.types, format: 'esm' }, plugins: [ dts({ @@ -67,7 +67,65 @@ const rollupConfig = defineConfig([ }), ], }, -]); +] as const satisfies ReadonlyArray; + +const MODERN_CONFIG = [ + { + input: PATH_INPUT_FILE, + output: [ + { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access + file: packageJson.exports.import.default, + format: 'esm', + sourcemap: !IS_PRODUCTION, + globals: GLOBALS, + }, + { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access + file: packageJson.exports.require.default, + name: packageJson.name, + format: 'umd', + sourcemap: !IS_PRODUCTION, + globals: GLOBALS, + }, + ], + plugins: [ + commonjs(), + typescript({ + tsconfig: PATH_TSCONFIG, + sourceMap: !IS_PRODUCTION, + }), + terser({ + output: { comments: false }, + compress: { + pure_getters: true, + }, + toplevel: true, + }), + ], + // Ensure dependencies are not bundled with the library + external: [...Object.keys(packageJson.peerDependencies)], + }, + { + input: PATH_INPUT_FILE, + output: [ + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access + { file: packageJson.exports.import.types, format: 'esm' }, + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access + { file: packageJson.exports.require.types, format: 'cjs' }, + ], + plugins: [ + dts({ + compilerOptions: { + baseUrl: './src', + paths: tsConfig.compilerOptions.paths, + }, + }), + ], + }, +] as const satisfies ReadonlyArray; + +const rollupConfig = defineConfig([...LEGACY_CONFIG, ...MODERN_CONFIG]); // eslint-disable-next-line export default rollupConfig;