Skip to content

Commit

Permalink
Add "exports" field to the package.json, fix UMD build, add Emojis CJS
Browse files Browse the repository at this point in the history
  • Loading branch information
arnautov-anton committed Oct 24, 2023
1 parent 80361d8 commit fd7a267
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 14 deletions.
20 changes: 16 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,28 @@
"type": "git",
"url": "https://github.com/GetStream/stream-chat-react.git"
},
"typings": "dist/index.d.ts",
"types": "dist/index.d.ts",
"main": "dist/index.cjs.js",
"module": "dist/index.js",
"jsnext:main": "dist/index.js",
"jsdelivr": "./dist/browser.full-bundle.min.js",
"exports": {
".": {
"types": "./dist/index.d.ts",
"require": "./dist/index.cjs.js",
"import": "./dist/index.js",
"default": "./dist/index.js"
},
"./emojis": {
"types": "./dist/components/Emojis/index.d.ts",
"require": "./dist/components/Emojis/index.cjs.js",
"import": "./dist/components/Emojis/index.js",
"default": "./dist/components/Emojis/index.js"
}
},
"style": "dist/css/v2/index.css",
"sideEffects": [
"*.css"
],
"source": "src/index.tsx",
"jsdelivr": "./dist/browser.full-bundle.min.js",
"keywords": [
"chat",
"messaging",
Expand Down
26 changes: 16 additions & 10 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable sort-keys */
import babel from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import image from '@rollup/plugin-image';
Expand All @@ -20,8 +21,10 @@ process.env.NODE_ENV = 'production';

const baseConfig = {
cache: false,
inlineDynamicImports: true,
input: 'src/index.ts',
input: {
index: 'src/index.ts',
'components/Emojis/index': 'src/components/Emojis/index.ts',
},
watch: {
chokidar: false,
},
Expand Down Expand Up @@ -89,30 +92,33 @@ const basePlugins = ({ useBrowserResolve = false }) => [
verbose: process.env.VERBOSE,
watch: process.env.ROLLUP_WATCH,
}),
// Json to ES modules conversion
// JSON to ES modules conversion
json({ compact: true }),
process.env.BUNDLE_SIZE ? visualizer() : null,
];

const normalBundle = {
...baseConfig,
external: externalDependencies,
output: [
{
file: pkg.main,
format: 'cjs',
sourcemap: true,
},
],
output: {
dir: 'dist',
format: 'cjs',
entryFileNames: '[name].[format].js',
},
plugins: [...basePlugins({ useBrowserResolve: false })],
};

// TODO: multiple separate bundles
const fullBrowserBundle = ({ min } = { min: false }) => ({
...baseConfig,
inlineDynamicImports: true,
// includes EmojiPicker
input: 'src/index_UMD.ts',
output: [
{
file: min ? pkg.jsdelivr : pkg.jsdelivr.replace('.min', ''),
format: 'iife',
// TODO: figure out emoji-mart globals
globals: {
react: 'React',
'react-dom': 'ReactDOM',
Expand Down
8 changes: 8 additions & 0 deletions src/index_UMD.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// entry file for Rollup for the UMD build \w Emojis
export * from './components';
export * from './context';
export * from './i18n';
// todo: distribute utils into separate files
export * from './utils';
export { getChannel } from './utils/getChannel';
export * from './components/Emojis';

0 comments on commit fd7a267

Please sign in to comment.