Skip to content

Commit fbf443d

Browse files
authored
feat: new build settings (#820)
Changelogs: - Changes have been made to export modules using the [sub-path exports](https://nodejs.org/api/packages.html#subpath-exports) in the package.json. If you were using the package in a Native CJS environment, this might have an impact. You can migrate the path as follows: ```diff - const ChannelList = require('@sendbird/uikit-react/cjs/ChannelList'); + const ChannelList = require('@sendbird/uikit-react/ChannelList'); ``` - TypeScript support has been improved. Now, precise types based on the source code are used. --- - Fix type errors in source. - Exports auto generated .d.ts files instead of manual `index.d.ts` file ### Before 1. run rollup 1. read inputs (module entries) 2. generate css and js files to - css: `/dist/dist/index.css`, `/dist/dist/cjs/dist/index.css` - js: `/dist` and `/dist/cjs` 3. copy `README.md`, `LICESNSE`, `CHANGELOG.md`, `index.d.ts` 2. run `scripts/post_build.js` 1. append version to `index.d.ts` 2. package.json: add dependencies and copy to `dist/package.json` ### After 1. run rollup 1. read inputs (module entries) 2. generate css and js files to - css: `/dist/dist/index.css`, `/dist/dist/cjs/dist/index.css` - js: `/dist` and `/dist/cjs` 3. copy `README.md`, `LICESNSE`, `CHANGELOG.md` 2. run `scripts/post_build.js` 1. package.json: add dependencies, exports, typesVersions and copy to `dist/package.json` 2. remove unused css files in `/dist/dist/cjs/dist` 3. build `.d.ts` files --- The biggest difference is that now we use the exports supported in package.json. You can find more information here: https://nodejs.org/api/packages.html#subpath-exports This may result in breaking changes because you can only use modules that are specified in exports. For example, the `@sendbird/chat/cjs/index.js` file actually exists, but it is not exported in package.json, so you cannot use it in a strict environment. The advantages of this approach are as follows: For paths that we directly specify in exports, files are assigned accordingly in the esm/cjs environment. Previously, for individually exported entries (modules) other than the main entry, we had to specify the path directly depending on the module environment. For example: > #### Before >esm: @sendbird/chat (package.json > module: "index.js") cjs: @sendbird/chat (package.json > main: "cjs/index.js") > >esm: @sendbird/chat/ChannelList (nothing in package.json) cjs: @sendbird/chat/cjs/ChannelList (nothing in package.json) > > #### After >esm: @sendbird/chat (package.json > exports: { ".": "index.js" } ) cjs: @sendbird/chat (package.json > exports: { ".": "cjs/index.js" } ) > >esm: @sendbird/chat/ChannelList (package.json > exports: { "./ChannelList": "ChannelList/index.js" } ) cjs: @sendbird/chat/ChannelList (package.json > exports: { "./ChannelList": "cjs/ChannelList/index.js" } ) --- package.json example ```json { "exports": { "./package.json": "./package.json", "./dist/index.css": "./dist/index.css", ".": { "types": "./types/index.d.ts", "require": "./cjs/index.js", "import": "./index.js", "default": "./index.js" }, "./App": { "types": "./types/modules/App/index.d.ts", "require": "./cjs/App.js", "import": "./App.js", "default": "./App.js" }, "./SendbirdProvider": { "types": "./types/lib/Sendbird.d.ts", "require": "./cjs/SendbirdProvider.js", "import": "./SendbirdProvider.js", "default": "./SendbirdProvider.js" }, "./sendbirdSelectors": { "types": "./types/lib/selectors.d.ts", "require": "./cjs/sendbirdSelectors.js", "import": "./sendbirdSelectors.js", "default": "./sendbirdSelectors.js" }, "./VoiceRecorder/context": { "types": "./types/hooks/VoiceRecorder/index.d.ts", "require": "./cjs/VoiceRecorder/context.js", "import": "./VoiceRecorder/context.js", "default": "./VoiceRecorder/context.js" }, "./VoiceRecorder/useVoiceRecorder": { "types": "./types/hooks/VoiceRecorder/useVoiceRecorder.d.ts", "require": "./cjs/VoiceRecorder/useVoiceRecorder.js", "import": "./VoiceRecorder/useVoiceRecorder.js", "default": "./VoiceRecorder/useVoiceRecorder.js" } } } ``` ```sh git rebase --onto main HEAD~13 ```
1 parent 575be99 commit fbf443d

File tree

86 files changed

+2968
-4076
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+2968
-4076
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ jobs:
8787
no_output_timeout: 15m
8888
name: Run test
8989
command: |
90-
yarn test
90+
yarn test --forceExit --runInBand
9191
- store_artifacts:
9292
path: coverage
9393
destination: coverage

README.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ We are introducing a new version of the Sendbird Chat UIKit. Version 3 features
1313
or if you're using yarn
1414
`yarn add @sendbird/uikit-react`
1515

16-
For typescript projects, add `node_modules/@sendbird/uikit-react/index.d.ts` to your `include` section in tsconfig file to get type definitions
17-
1816
## Getting Started
1917

2018
With Sendbird UI Kit React, we export these components:
@@ -122,13 +120,6 @@ yarn run lint
122120
```
123121
* .eslintrc.json lints ts files and .eslintrc.js lints js files
124122

125-
126-
### Typescript
127-
128-
* We are trying to progressively move our source code to typescript - which means older JS code and newly written TS code will coxist while we migrate older JS code to TS
129-
* .eslintrc.json lints ts files and .eslintrc.js lints js files
130-
* Type definition file can be `scripts/index.d.ts` which will be copied to `/dist` directory
131-
132123
### Webpack 5
133124

134125
Webpack 5 removes stream and buffer componets from default polyfill
@@ -161,7 +152,6 @@ To read more: https://webpack.js.org/configuration/resolve/#resolvefallback
161152
'NewComponent/SubComponent': 'location/of/NewComponent/SubComponent',
162153
```
163154
- This component can be imported by the consumer as: `import SubComponent from '@sendbird/uikit-react/NewComponent/SubComponent';`
164-
4. Add type definitions to `scripts/index.d.ts`.
165155
166156
### Scaffolding New Components
167157

babel.config.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,10 @@ module.exports = {
44
'@babel/preset-react',
55
'@babel/preset-typescript',
66
],
7-
plugins: ['@babel/plugin-proposal-class-properties', '@babel/plugin-syntax-export-default-from'],
7+
plugins: [
8+
'@babel/plugin-proposal-class-properties',
9+
'@babel/plugin-syntax-export-default-from',
10+
'@babel/plugin-proposal-private-methods',
11+
'@babel/plugin-proposal-private-property-in-object',
12+
],
813
};

package.json

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@
5353
"stylelint": "stylelint 'src/**'",
5454
"generate-component": "plop",
5555
"deploy-storybook": "storybook-to-ghpages",
56-
"inspect": "yarn test; yarn lint;",
57-
"bundle": "dts-bundle-generator -o ./dist/my.d.ts ./src/index.d.ts"
56+
"inspect": "yarn test; yarn lint;"
5857
},
5958
"repository": {
6059
"type": "git",
@@ -78,27 +77,27 @@
7877
},
7978
"homepage": "https://sendbird.com",
8079
"devDependencies": {
81-
"@babel/core": "^7.8.4",
82-
"@babel/eslint-parser": "^7.21.8",
83-
"@babel/plugin-proposal-class-properties": "^7.8.3",
84-
"@babel/plugin-proposal-export-default-from": "^7.8.3",
85-
"@babel/preset-env": "^7.8.3",
86-
"@babel/preset-react": "^7.8.3",
87-
"@babel/preset-typescript": "^7.10.4",
88-
"@rollup/plugin-babel": "^5.3.0",
89-
"@rollup/plugin-commonjs": "^19.0.0",
90-
"@rollup/plugin-eslint": "^8.0.1",
91-
"@rollup/plugin-node-resolve": "^7.1.3",
92-
"@rollup/plugin-replace": "^2.4.2",
93-
"@rollup/plugin-typescript": "^8.2.1",
80+
"@babel/core": "^7.23.2",
81+
"@babel/eslint-parser": "^7.22.15",
82+
"@babel/plugin-proposal-class-properties": "^7.18.6",
83+
"@babel/plugin-proposal-export-default-from": "^7.22.17",
84+
"@babel/preset-env": "^7.23.2",
85+
"@babel/preset-react": "^7.22.15",
86+
"@babel/preset-typescript": "^7.23.2",
87+
"@rollup/plugin-babel": "^6.0.4",
88+
"@rollup/plugin-commonjs": "^25.0.7",
89+
"@rollup/plugin-eslint": "^9.0.5",
90+
"@rollup/plugin-node-resolve": "^15.2.3",
91+
"@rollup/plugin-replace": "^5.0.4",
92+
"@rollup/plugin-typescript": "^11.1.5",
9493
"@storybook/addon-actions": "^6.5.10",
9594
"@storybook/addon-docs": "^6.5.10",
9695
"@storybook/addon-links": "^6.5.10",
9796
"@storybook/addons": "^6.5.10",
9897
"@storybook/preset-scss": "^1.0.3",
9998
"@storybook/react": "^6.5.10",
10099
"@storybook/storybook-deployer": "^2.8.12",
101-
"@svgr/rollup": "^5.5.0",
100+
"@svgr/rollup": "^8.1.0",
102101
"@svgr/webpack": "^5.1.0",
103102
"@testing-library/jest-dom": "^5.16.5",
104103
"@testing-library/react": "^13.4.0",
@@ -111,7 +110,6 @@
111110
"browserslist": "^4.14.5",
112111
"caniuse-lite": "^1.0.30001148",
113112
"css-loader": "^3.4.2",
114-
"dts-bundle-generator": "^6.5.0",
115113
"eslint": "^8.40.0",
116114
"eslint-config-airbnb": "^19.0.4",
117115
"eslint-config-airbnb-base": "^15.0.0",
@@ -132,19 +130,18 @@
132130
"postcss": "^8.3.5",
133131
"react": "^18.2.0",
134132
"react-dom": "^18.2.0",
135-
"rollup": "^2.53.1",
133+
"rollup": "^4.1.4",
136134
"rollup-plugin-analyzer": "^4.0.0",
137-
"rollup-plugin-copy": "^3.4.0",
138-
"rollup-plugin-polyfill-node": "^0.10.1",
139-
"rollup-plugin-postcss": "^4.0.0",
140-
"rollup-plugin-scss": "^3.0.0",
141-
"rollup-plugin-visualizer": "^5.9.0",
135+
"rollup-plugin-copy": "^3.5.0",
136+
"rollup-plugin-polyfill-node": "^0.12.0",
137+
"rollup-plugin-postcss": "^4.0.2",
138+
"rollup-plugin-scss": "^4.0.0",
139+
"rollup-plugin-typescript2": "^0.36.0",
140+
"rollup-plugin-visualizer": "^5.9.2",
142141
"sass": "^1.55.0",
143142
"sass-loader": "^10.2.0",
144-
"style-loader": "^1.1.3",
145143
"stylelint": "^13.0.0",
146144
"stylelint-config-sass-guidelines": "^7.0.0",
147-
"ts-loader": "^7.0.5",
148145
"ts-pattern": "^4.2.2",
149146
"tslib": "^2.0.0",
150147
"typescript": "^4.7.4"

rollup.config.js

Lines changed: 0 additions & 131 deletions
This file was deleted.

rollup.config.mjs

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// plugins
2+
import commonjs from "@rollup/plugin-commonjs";
3+
import resolve from "@rollup/plugin-node-resolve";
4+
import svgr from "@svgr/rollup";
5+
import scss from "rollup-plugin-scss";
6+
import postcss from "rollup-plugin-postcss";
7+
import replace from "@rollup/plugin-replace";
8+
import autoprefixer from "autoprefixer";
9+
import copy from "rollup-plugin-copy";
10+
import nodePolyfills from "rollup-plugin-polyfill-node";
11+
import {visualizer} from "rollup-plugin-visualizer";
12+
import ts2 from "rollup-plugin-typescript2"
13+
14+
// config from package.json
15+
import pkg from "./package.json" assert {type: "json"};
16+
import inputs from "./rollup.module-exports.mjs";
17+
18+
const APP_VERSION_STRING = "__react_dev_mode__";
19+
20+
export default {
21+
// To bundle split
22+
input: inputs,
23+
output: [
24+
{
25+
dir: "./dist",
26+
chunkFileNames: 'chunks/bundle-[hash].js',
27+
format: "esm",
28+
sourcemap: true,
29+
},
30+
{
31+
dir: "./dist/cjs",
32+
chunkFileNames: 'chunks/bundle-[hash].js',
33+
format: "cjs",
34+
sourcemap: true,
35+
},
36+
],
37+
external: [
38+
"@sendbird/chat",
39+
"@sendbird/chat/groupChannel",
40+
"@sendbird/chat/openChannel",
41+
"@sendbird/chat/message",
42+
"@sendbird/uikit-tools",
43+
"react",
44+
"react-dom",
45+
"css-vars-ponyfill",
46+
"date-fns",
47+
"dompurify",
48+
// todo@v4: remove this
49+
// we do not add ts-pattern as dep to avoid conflict with client base
50+
// 'ts-pattern',
51+
],
52+
plugins: [
53+
postcss({
54+
preprocessor: (content, id) =>
55+
new Promise((resolvecss) => {
56+
const result = scss.renderSync({ file: id });
57+
resolvecss({ code: result.css.toString() });
58+
}),
59+
plugins: [autoprefixer],
60+
sourceMap: true,
61+
extract: "dist/index.css",
62+
extensions: [".sass", ".scss", ".css"],
63+
}),
64+
replace({
65+
preventAssignment: false,
66+
exclude: "node_modules/**",
67+
[APP_VERSION_STRING]: pkg.version,
68+
}),
69+
ts2({
70+
tsconfig: 'tsconfig.json',
71+
tsconfigOverride: {
72+
compilerOptions:{
73+
declaration: false,
74+
}
75+
}
76+
}),
77+
svgr(),
78+
resolve({
79+
preferBuiltins: true,
80+
}),
81+
commonjs(),
82+
nodePolyfills({
83+
include: ["buffer", "stream"],
84+
}),
85+
copy({
86+
verbose: true,
87+
targets: [
88+
{
89+
src: "./README.md",
90+
dest: "dist",
91+
},
92+
{
93+
src: "./LICENSE",
94+
dest: "dist",
95+
},
96+
{
97+
src: "./CHANGELOG.md",
98+
dest: "dist",
99+
},
100+
],
101+
}),
102+
visualizer({
103+
filename: "bundle-analysis.json",
104+
gzipSize: true,
105+
template: "raw-data",
106+
brotliSize: false,
107+
}),
108+
// Uncomment the below line, if you want to see box-graph of bundle size
109+
// visualizer(),
110+
],
111+
};

0 commit comments

Comments
 (0)