Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance build time for bezier-react #1424

Merged
merged 32 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
01626b1
chore(deps): remove unused package
sungik-choi Jun 15, 2023
46c00aa
chore(deps): update react-textarea-autosize
sungik-choi Jun 15, 2023
802522d
chore(deps): update rollup
sungik-choi Jun 15, 2023
66571ff
chore(deps): update '@rollup/*' packages
sungik-choi Jun 15, 2023
11ef7c9
build(bezier-react): change build dir from build to dist
sungik-choi Jun 15, 2023
ec81d20
build(babel): use preset-react useBuildtIns option
sungik-choi Jun 15, 2023
fcf58e5
build(babel): remove cross-env package and change babel config
sungik-choi Jun 15, 2023
d1de2cd
chore(rollup): change from .js to .mjs
sungik-choi Jun 15, 2023
716c7c2
chore(deps): update rollup-plugin-visualizer
sungik-choi Jun 15, 2023
e2d3e35
chore(deps): update '@babel/*' packages
sungik-choi Jun 15, 2023
edfb3dd
chore(tsconfig): change declarationDir from build to dist
sungik-choi Jun 15, 2023
264f23e
chore(gitignore): add rollup cache
sungik-choi Jun 15, 2023
accd45a
build(rollup): change to using the rollup plugin typescript to genera…
sungik-choi Jun 15, 2023
8b00fce
fix(textarea): remove unnecessary bypass code due to rollup commonjs …
sungik-choi Jun 15, 2023
ee0899f
build(rollup): remove unnecessary nodeResolve options and unify rollu…
sungik-choi Jun 15, 2023
73755af
build(rollup): changes to rollup settings and TypeScript type generat…
sungik-choi Jun 15, 2023
0a0ba7b
build(tsc): enhance build command and type declaration build setting
sungik-choi Jun 15, 2023
f23a19f
build: remove unused package and add ttypescript to resolve alias pat…
sungik-choi Jun 15, 2023
b4eed25
chore(scripts): change dir of clean:build
sungik-choi Jun 15, 2023
ef7cb6e
chore(yarn): install
sungik-choi Jun 19, 2023
10c9213
chore(tsconfig): delete json comments
sungik-choi Jun 19, 2023
4a1b498
chore(deps): update babel-* packages
sungik-choi Jun 19, 2023
ed994fa
build(babel): remove unnecessary plugins embedded in preset-env
sungik-choi Jun 19, 2023
7b12521
build(rollup): use skipPreflightCheck's default option and add commen…
sungik-choi Jun 19, 2023
63f4232
build(rollup): change the peerDeps package to the maintained node ext…
sungik-choi Jun 19, 2023
7f0f797
build(package): add bezier-icons to peerDeps and peerDepsMeta
sungik-choi Jun 19, 2023
97922ad
build(tsconfig): change to support es2020
sungik-choi Jun 19, 2023
99968e1
test(jest): add a temp solution of type error of react-textarea-autosize
sungik-choi Jun 19, 2023
d14647f
chore(scripts): revert
sungik-choi Jun 19, 2023
1931a7c
chore(bezier-react): remove ununsed package
sungik-choi Jun 19, 2023
01b53c2
build(bezier-icons): change to using the node resolve plugin to resol…
sungik-choi Jun 19, 2023
5dc1e54
chore(changeset): add changeset
sungik-choi Jun 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ $RECYCLE.BIN/
*.lnk

# Build files
build/
dist/

# Story book
storybook-static/
Expand All @@ -212,3 +212,6 @@ stats.html

# Stylelint cache
.stylelintcache

# Rollup cache
.rollup.cache
13 changes: 7 additions & 6 deletions packages/bezier-icons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,22 @@
"author": "Channel Corp.",
"license": "Apache-2.0",
"devDependencies": {
"@babel/preset-env": "^7.21.5",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.21.5",
"@babel/core": "^7.22.5",
"@babel/preset-env": "^7.22.5",
"@babel/preset-react": "^7.22.5",
"@babel/preset-typescript": "^7.22.5",
"@rollup/plugin-alias": "^5.0.0",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-node-resolve": "^15.1.0",
"@rollup/plugin-terser": "^0.4.3",
"@rollup/plugin-typescript": "^11.1.1",
"@rollup/plugin-virtual": "^3.0.1",
"@rollup/pluginutils": "^5.0.2",
"@svgr/core": "^8.0.0",
"@svgr/plugin-jsx": "^8.0.1",
"eslint-config-bezier": "workspace:^",
"jest": "^29.5.0",
"rollup": "^3.22.0",
"rollup-plugin-visualizer": "^5.9.0",
"rollup": "^3.25.1",
"rollup-plugin-visualizer": "^5.9.2",
"svgo": "^3.0.2",
"tsconfig": "workspace:^"
}
Expand Down
9 changes: 6 additions & 3 deletions packages/bezier-icons/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import * as fs from 'fs'
import * as path from 'path'

import { DEFAULT_EXTENSIONS } from '@babel/core'
import alias from '@rollup/plugin-alias'
import { babel } from '@rollup/plugin-babel'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import terser from '@rollup/plugin-terser'
import typescript from '@rollup/plugin-typescript'
import virtual from '@rollup/plugin-virtual'
import { createFilter } from '@rollup/pluginutils'
import { transform } from '@svgr/core'
import { defineConfig } from 'rollup'
import { visualizer } from 'rollup-plugin-visualizer'
import { optimize } from 'svgo'

const extensions = [...DEFAULT_EXTENSIONS, '.ts', '.tsx', '.svg']

const config = {
input: {
icons: 'icons',
Expand Down Expand Up @@ -269,7 +272,7 @@ export default defineConfig({
external: ['react'],
plugins: [
virtual({ 'src/index.ts': entryModuleContent }),
typescript(),
nodeResolve({ extensions }),
svgBuild({ include: `${iconBasePath}/*.svg` }),
/**
* Module resolution is not working well inside the virtual module, so use the alias plugin to resolve the module manually.
Expand All @@ -282,7 +285,7 @@ export default defineConfig({
}),
babel({
exclude: 'node_modules/**',
extensions: ['.js', '.jsx', '.ts', '.tsx', '.svg'],
extensions,
envName: 'production',
babelHelpers: 'bundled',
}),
Expand Down
2 changes: 1 addition & 1 deletion packages/bezier-react/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node_modules
build
dist
coverage
__mocks__
37 changes: 18 additions & 19 deletions packages/bezier-react/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
module.exports = {
env: {
build: {
presets: [
['@babel/preset-env'],
'@babel/preset-react',
['@babel/preset-typescript', { isTSX: true, allExtensions: true }],
],
plugins: [
'@babel/plugin-transform-runtime',
['@babel/plugin-proposal-private-property-in-object', { loose: false }],
['@babel/plugin-proposal-class-properties', { loose: false }],
['babel-plugin-styled-components', {
minify: true,
pure: true,
topLevelImportPaths: ['~/src/foundation'],
}],
],
},
},
presets: [
['@babel/preset-env', { useBuiltIns: 'entry', corejs: '3.31.0', bugfixes: true }],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • @babel/plugin-proposal-private-property-in-object, @babel/plugin-proposal-class-properties 플러그인은 preset-env ES2022에 내장되었으므로 제거
  • 폴리필을 위한 corejs 활성화
  • 번들 사이즈 감소를 위한 bugfixes 옵션 활성화 (More info: https://github.com/babel/preset-modules)

/**
* Will use the native built-in instead of trying to polyfill behavior for any plugins that require one.
* Remove the helper function for Object.assign.
* @see https://babeljs.io/docs/babel-preset-react#usebuiltins
*/
['@babel/preset-react', { useBuiltIns: true }],
['@babel/preset-typescript', { isTSX: true, allExtensions: true }],
],
plugins: [
'@babel/plugin-transform-runtime',
['babel-plugin-styled-components', {
minify: true,
pure: true,
topLevelImportPaths: ['~/src/foundation'],
}],
],
}
8 changes: 8 additions & 0 deletions packages/bezier-react/jest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,11 @@ afterEach(() => {
// @ts-ignore
window.requestAnimationFrame.mockRestore()
})

/**
* react-textarea-autosize@8.4.1 uses the APIs below, but the DOM in jest (JSDOM) hasn't implemented them.
* @see https://github.com/Andarist/react-textarea-autosize/issues/368
*/
Object.defineProperty(document, 'fonts', {
value: { addEventListener() {}, removeEventListener() {} },
})
78 changes: 45 additions & 33 deletions packages/bezier-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,26 @@
"url": "https://github.com/channel-io/bezier-react",
"directory": "packages/bezier-react"
},
"main": "build/index.cjs.js",
"module": "build/src/index.js",
"types": "build/src/index.d.ts",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.mjs",
Copy link
Contributor Author

@sungik-choi sungik-choi Jun 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type="module" 이 아니라면, 즉, CJS 패키지라면 ESM 모듈엔 mjs 로 분명하게 확장자를 명시해주어야합니다. bezier-icons 패키지에도 마찬가지로 적용되어 있습니다.

"types": "dist/types/index.d.ts",
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"require": "./dist/cjs/index.js",
"import": "./dist/esm/index.mjs"
}
},
"sideEffects": false,
"files": [
"build",
"dist",
"!dist/*.tsbuildinfo",
Copy link
Contributor Author

@sungik-choi sungik-choi Jun 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dist 내부에 포함되어있는 ts build log는 파일에 포함하지 않습니다.

"src"
],
"scripts": {
"build": "cross-env BABEL_ENV=production rollup -c",
"build": "run-p 'build:*'",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rollup을 통한 자바스크립트 번들링, ttsc(ttypescript)를 통한 타입 생성을 병렬로 수행합니다.

"build:js": "rollup -c",
"build:types": "ttsc --build --verbose ./tsconfig.build.json",
"dev": "yarn storybook",
"lint": "run-p 'lint:*'",
"lint:js": "TIMING=1 eslint --cache .",
Expand All @@ -28,7 +38,7 @@
"test:watch": "jest --watch",
"update-snapshot": "jest --updateSnapshot",
"clean": "run-s 'clean:*'",
"clean:build": "rm -rf build",
"clean:build": "rm -rf dist",
"clean:cache": "rm -rf node_modules .turbo .eslintcache .stylelintcache tsconfig.tsbuildinfo coverage",
"prebuild": "yarn clean:build",
"storybook": "start-storybook -p 4101",
Expand All @@ -49,18 +59,20 @@
"not ie <= 11"
],
"devDependencies": {
"@babel/core": "^7.20.2",
"@babel/plugin-proposal-class-properties": "^7.13.0",
"@babel/plugin-transform-runtime": "^7.12.15",
"@babel/preset-env": "^7.14.2",
"@babel/preset-react": "^7.12.10",
"@babel/preset-typescript": "^7.12.7",
"@babel/core": "^7.22.5",
"@babel/plugin-transform-runtime": "^7.22.5",
"@babel/preset-env": "^7.22.5",
"@babel/preset-react": "^7.22.5",
"@babel/preset-typescript": "^7.22.5",
"@channel.io/bezier-icons": "^0.2.0",
"@channel.io/react-docgen-typescript-plugin": "^1.0.0",
"@mdx-js/react": "^1.6.22",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-commonjs": "^19.0.0",
"@rollup/plugin-node-resolve": "^13.0.0",
"@rollup/plugin-url": "^6.0.0",
"@rollup/plugin-alias": "^5.0.0",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-commonjs": "^25.0.1",
"@rollup/plugin-node-resolve": "^15.1.0",
"@rollup/plugin-typescript": "^11.1.1",
"@rollup/plugin-url": "^8.0.1",
"@storybook/addon-a11y": "^6.5.0",
"@storybook/addon-actions": "^6.5.13",
"@storybook/addon-backgrounds": "^6.5.13",
Expand All @@ -81,13 +93,11 @@
"@types/react-dom": "^18.0.3",
"@types/styled-components": "^5.1.5",
"@types/uuid": "^9.0.0",
"babel-eslint": "^10.1.0",
"babel-loader": "^9.1.0",
"babel-plugin-styled-components": "^2.0.7",
"babel-preset-react-app": "^10.0.0",
"babel-loader": "^9.1.2",
"babel-plugin-styled-components": "^2.1.3",
"babel-preset-react-app": "^10.0.1",
"chromatic": "^6.11.4",
"core-js": "^3.8.1",
"cross-env": "^7.0.3",
"core-js": "^3.31.0",
"eslint-config-bezier": "workspace:*",
"eslint-plugin-storybook": "^0.6.0",
"identity-obj-proxy": "^3.0.0",
Expand All @@ -97,26 +107,29 @@
"react": "^18.1.0",
"react-dom": "^18.1.0",
"regenerator-runtime": "^0.13.11",
"rollup": "^2.50.5",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-typescript2": "^0.31.1",
"rollup-plugin-visualizer": "^5.8.3",
"rollup": "^3.25.1",
"rollup-plugin-node-externals": "^6.1.1",
"rollup-plugin-visualizer": "^5.9.2",
"styled-components": "^5.3.5",
"ts-prune": "^0.10.3",
"tsconfig": "workspace:*",
"tsconfig-paths-webpack-plugin": "^3.5.2",
"tslib": "^2.3.1",
"ttypescript": "^1.5.13",
"typescript-transform-paths": "^3.3.1"
"ttypescript": "^1.5.15",
"typescript-transform-paths": "^3.4.6"
},
"peerDependencies": {
"@channel.io/bezier-icons": ">=0.2.0",
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0",
"styled-components": ">=5"
},
"peerDependenciesMeta": {
"@channel.io/bezier-icons": {
"optional": true
}
},
Comment on lines 120 to +130
Copy link
Contributor Author

@sungik-choi sungik-choi Jun 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why move bezier-icons from deps to peerDeps

#1411

bezier-react에 peer dependency로 bezier-icons를 추가하는 방식으로 문제를 해결할 수도 있습니다. 하지만 bezier-icons는 bezier-react와 꼭 쌍으로 사용해야하는 패키지가 아니고, bezier-react를 사용하는 사용처에서도 아이콘을 사용하지 않음에도 bezier-icons를 설치해야하는 불편함이 발생하게 됩니다.

  • peerDependenciesMeta 옵션 설정을 통해, bezier-icons가 설치된 패키지에서만 fix: change the identifier of the bezier icon to a string literal instead of a symbol #1411 의 문제가 발생하지 않는 버전을 강제할 수 있습니다. 따라서 위에 언급한 불편함이 어느정도 해소될 거라고 판단했습니다.
  • 불필요한 트랜스파일링 과정을 거치지 않아도 됩니다. (babel에 exclude 옵션이 있으나, yarn workspace 내부 패키지에는 symlink로 연결되어 잘 적용되지 않는 문제가 있었습니다.)
  • 내부적으로 ChevronIcon을 사용하는 Select 같은 컴포넌트의 케이스에서 bezier-icons 의존성 추가없이 사용할 경우 문제가 될 수 있습니다. 이 경우 개발 서버 및 빌드 과정에서 module resolve 에러가 발생할 것이므로 프로덕션에서 문제가 발생할 가능성은 낮다고 판단했습니다.

"dependencies": {
"@babel/runtime": "^7.12.13",
"@channel.io/bezier-icons": "^0.2.0",
"@babel/runtime": "^7.22.5",
"@radix-ui/react-checkbox": "^1.0.3",
"@radix-ui/react-dialog": "^1.0.2",
"@radix-ui/react-radio-group": "^1.1.0",
Expand All @@ -129,9 +142,8 @@
"@radix-ui/react-visually-hidden": "^1.0.2",
"classnames": "^2.3.2",
"react-resize-detector": "^7.1.1",
"react-textarea-autosize": "^8.3.4",
"react-textarea-autosize": "^8.4.1",
"ssr-window": "^3.0.0",
"typesafe-actions": "^5.1.0",
"uuid": "^9.0.0"
}
}
105 changes: 0 additions & 105 deletions packages/bezier-react/rollup.config.js

This file was deleted.

Loading