Skip to content

Commit 35386e8

Browse files
authored
Support tree shaking (#74)
1 parent 2e69edf commit 35386e8

File tree

17 files changed

+2160
-390
lines changed

17 files changed

+2160
-390
lines changed

babel.config.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
env: {
3+
test: {
4+
presets: [
5+
['@babel/preset-env', { targets: { node: 'current' } }],
6+
'@babel/preset-react',
7+
['@babel/preset-typescript', { isTSX: true, allExtensions: true }],
8+
],
9+
},
10+
build: {
11+
presets: [
12+
['@babel/preset-env'],
13+
'@babel/preset-react',
14+
['@babel/preset-typescript', { isTSX: true, allExtensions: true }],
15+
],
16+
},
17+
},
18+
}

jest.config.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
module.exports = {
2-
roots: ["./src"],
3-
setupFilesAfterEnv: ["./jest.setup.ts"],
4-
moduleFileExtensions: ["ts", "tsx", "js"],
5-
testPathIgnorePatterns: ["node_modules/"],
2+
roots: ['./src'],
3+
setupFilesAfterEnv: ['./jest.setup.ts'],
4+
moduleFileExtensions: ['ts', 'tsx', 'js'],
5+
testPathIgnorePatterns: ['node_modules/'],
6+
transformIgnorePatterns: [],
67
transform: {
7-
"^.+\\.tsx?$": "ts-jest",
8+
'^.+\\.[t|j]sx?$': 'babel-jest',
89
},
9-
testMatch: ["**/*.test.(ts|tsx)"],
10+
testMatch: ['**/*.test.(ts|tsx)'],
1011
moduleNameMapper: {
11-
"\\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
12-
"identity-obj-proxy",
13-
"\\.(css|less|scss|sass)$": "identity-obj-proxy"
14-
}
12+
'\\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
13+
'identity-obj-proxy',
14+
'\\.(css|less|scss|sass)$': 'identity-obj-proxy',
15+
},
1516
}

package-lock.json

Lines changed: 2038 additions & 338 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
},
99
"main": "build/index.js",
1010
"module": "build/index.es.js",
11+
"sideEffects": false,
1112
"types": "build/index.d.ts",
1213
"files": [
1314
"build"
@@ -21,9 +22,10 @@
2122
"stylelint-all": "stylelint src/**/*.styled.{js,ts}",
2223
"typecheck": "tsc",
2324
"test": "npm run lint && npm run typecheck && npm run jest",
24-
"jest": "jest",
25-
"jest:watch": "jest --watch",
26-
"build": "rollup -c",
25+
"jest": "cross-env BABEL_ENV=test jest",
26+
"jest:watch": "cross-env BABEL_ENV=test jest --watch",
27+
"build": "cross-env BABEL_ENV=build rollup -c",
28+
"prebuild": "npm run typecheck",
2729
"prepublishOnly": "npm run build",
2830
"build:storybook": "build-storybook",
2931
"build:icon": "./scripts/build-icon.sh",
@@ -54,11 +56,21 @@
5456
],
5557
"author": "",
5658
"license": "ISC",
59+
"browserslist": [
60+
"ie >= 11",
61+
"> 1% in KR",
62+
"> 1% in JP",
63+
"> 1% in US"
64+
],
5765
"devDependencies": {
58-
"@babel/core": "^7.9.6",
66+
"@babel/core": "^7.10.5",
67+
"@babel/preset-env": "^7.10.4",
68+
"@babel/preset-react": "^7.10.4",
69+
"@babel/preset-typescript": "^7.10.4",
5970
"@channel.io/eslint-config": "^1.0.5",
6071
"@channel.io/stylelint-config": "^1.1.0",
61-
"@rollup/plugin-commonjs": "^11.1.0",
72+
"@rollup/plugin-babel": "^5.1.0",
73+
"@rollup/plugin-commonjs": "^11.0.2",
6274
"@rollup/plugin-node-resolve": "^7.1.3",
6375
"@storybook/addon-actions": "^5.3.19",
6476
"@storybook/addon-knobs": "^5.3.19",
@@ -70,16 +82,17 @@
7082
"@testing-library/jest-dom": "^5.5.0",
7183
"@testing-library/react": "^10.0.4",
7284
"@types/jest": "^25.2.1",
73-
"@types/lodash": "^4.14.155",
85+
"@types/lodash-es": "^4.17.3",
7486
"@types/react": "^16.9.34",
7587
"@types/styled-components": "^5.1.0",
7688
"@typescript-eslint/eslint-plugin": "^2.34.0",
7789
"@typescript-eslint/parser": "^2.34.0",
7890
"babel-eslint": "^8.2.6",
79-
"babel-jest": "^26.0.1",
91+
"babel-jest": "^26.2.2",
8092
"babel-loader": "^8.1.0",
8193
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
8294
"babel-preset-react-app": "^9.1.2",
95+
"cross-env": "^7.0.2",
8396
"eslint": "^5.16.0",
8497
"eslint-config-airbnb-typescript": "^4.0.1",
8598
"eslint-import-resolver-webpack": "^0.10.1",
@@ -93,22 +106,22 @@
93106
"identity-obj-proxy": "^3.0.0",
94107
"jest": "^26.0.1",
95108
"lint-staged": "^10.2.10",
96-
"lodash": "^4.17.15",
97109
"react": "^16.13.1",
98110
"react-dom": "^16.13.1",
99111
"regenerator-runtime": "^0.13.5",
100112
"rollup": "^2.8.2",
101113
"rollup-plugin-peer-deps-external": "^2.2.2",
102-
"rollup-plugin-typescript2": "^0.27.0",
103114
"styled-components": "^5.1.0",
104115
"stylelint": "^13.6.0",
105-
"ts-jest": "^25.5.0",
106116
"ts-node": "^8.10.2",
107117
"typescript": "^3.8.3"
108118
},
109119
"peerDependencies": {
110120
"react": ">=16.8.0",
111121
"react-dom": ">=16.8.0",
112122
"styled-components": ">=5"
123+
},
124+
"dependencies": {
125+
"lodash-es": "^4.17.15"
113126
}
114127
}

rollup.config.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
import { DEFAULT_EXTENSIONS } from '@babel/core'
12
import peerDepsExternal from 'rollup-plugin-peer-deps-external'
23
import resolve from '@rollup/plugin-node-resolve'
3-
import ts from 'rollup-plugin-typescript2'
4+
import babel from '@rollup/plugin-babel'
45
import commonjs from '@rollup/plugin-commonjs'
56

67
import packageJson from './package.json'
78

9+
const extensions = DEFAULT_EXTENSIONS.concat(['.ts', '.tsx'])
10+
811
export default {
912
input: 'src/index.ts',
1013
output: [
@@ -21,8 +24,13 @@ export default {
2124
],
2225
plugins: [
2326
peerDepsExternal(),
24-
resolve(),
27+
resolve({
28+
extensions,
29+
}),
2530
commonjs(),
26-
ts({ useTsconfigDeclarationDir: true }),
31+
babel({
32+
exclude: 'node_modules/**',
33+
extensions,
34+
}),
2735
],
2836
}

scripts/icon-index-template.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const _ = require('lodash')
1+
const _ = require('lodash-es')
22
const path = require('path')
33

44
function defaultIndexTemplate(filePaths) {

src/components/Button/Button.types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ export enum ButtonTheme {
22
Normal = 'normal'
33
}
44

5-
export interface ButtonProps {
5+
interface ButtonProps {
66
theme?: ButtonTheme
77
onClick?: () => void
88
}
9+
10+
export type {
11+
ButtonProps,
12+
}

src/components/Button/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import Button from './Button'
2-
import { ButtonProps, ButtonTheme } from './Button.types'
2+
import { ButtonTheme } from './Button.types'
3+
import type { ButtonProps } from './Button.types'
4+
5+
export type {
6+
ButtonProps,
7+
}
38

49
export {
510
Button,
6-
ButtonProps,
711
ButtonTheme,
812
}

src/components/Icon/Icon.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* External dependencies */
22
import React, { memo } from 'react'
3-
import _ from 'lodash'
43

54
/* Internal dependencies */
65
import IconProps, { IconSize } from './Icon.types'
@@ -20,7 +19,7 @@ function Icon({
2019
marginLeft = 0,
2120
...props
2221
}: IconProps) {
23-
if (_.isNil(icons[name])) { return null }
22+
if (!icons[name]) { return null }
2423

2524
return (
2625
<Styled

src/components/Icon/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
/* Internal dependencies */
22
import Icon from './Icon'
3-
import IconProps, { IconSize } from './Icon.types'
4-
import { IconName } from './generated'
3+
import { IconSize } from './Icon.types'
4+
import type IconProps from './Icon.types'
5+
import type { IconName } from './generated'
6+
7+
export type {
8+
IconProps,
9+
IconName,
10+
}
511

612
export {
713
Icon,
8-
IconProps,
914
IconSize,
10-
IconName,
1115
}

0 commit comments

Comments
 (0)