Skip to content

Commit 44f27fb

Browse files
authored
refactor: use rollup (#760)
* refactor: use rollup * chore: use sourcemaps files * fix: increase size limit
1 parent 6b45479 commit 44f27fb

File tree

5 files changed

+173
-2375
lines changed

5 files changed

+173
-2375
lines changed

.size-limit

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
33
"path": "dist/index.js",
4-
"limit": "2 KB",
4+
"limit": "2.5 KB",
55
"webpack": false,
66
"running": false
77
},
@@ -12,13 +12,13 @@
1212
},
1313
{
1414
"path": "dist/index.modern.js",
15-
"limit": "1.8 KB",
15+
"limit": "2.3 KB",
1616
"webpack": false,
1717
"running": false
1818
},
1919
{
2020
"path": "dist/index.modern.js",
21-
"limit": "9.3 KB",
21+
"limit": "9.4 KB",
2222
"import": "ChartComponent"
2323
}
2424
]

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"name": "react-chartjs-2",
33
"version": "3.0.5",
44
"description": "React components for Chart.js",
5-
"source": "src/index.tsx",
65
"main": "dist/index.js",
76
"module": "dist/index.modern.js",
87
"author": "Jeremy Ayerst",
@@ -24,16 +23,14 @@
2423
"react-chart.js"
2524
],
2625
"scripts": {
27-
"build": "microbundle-crl --no-compress --format modern,cjs",
28-
"start": "microbundle-crl watch --no-compress --format modern,cjs",
29-
"dev": "microbundle-crl --no-compress --no-sourcemap watch",
26+
"emitDeclarations": "tsc --skipLibCheck --emitDeclarationOnly",
27+
"build": "rollup -c & yarn emitDeclarations",
3028
"prepublishOnly": "yarn build",
3129
"test:lint": "eslint 'src/**/*.{ts,tsx}' 'test/**/*.{ts,tsx}'",
3230
"test:unit": "jest -c jest.config.json",
33-
"test:types": "tsc --skipLibCheck --noEmit",
34-
"test:size": "size-limit",
3531
"test:build": "yarn build",
36-
"test": "yarn test:lint && yarn test:unit && yarn test:types && yarn test:build && yarn test:size",
32+
"test:size": "size-limit",
33+
"test": "yarn test:lint && yarn test:unit && yarn test:build && yarn test:size",
3734
"format": "prettier --write src",
3835
"predeploy": "cd example && yarn && yarn build",
3936
"deploy": "gh-pages -d example/build",
@@ -47,8 +44,10 @@
4744
"react": "^16.8.0 || ^17.0.0"
4845
},
4946
"devDependencies": {
47+
"@rollup/plugin-node-resolve": "^13.0.5",
5048
"@size-limit/preset-big-lib": "^6.0.3",
5149
"@swc/core": "^1.2.95",
50+
"@swc/helpers": "^0.2.13",
5251
"@swc/jest": "^0.2.4",
5352
"@testing-library/jest-dom": "^5.5.0",
5453
"@testing-library/react": "^12.1.2",
@@ -57,7 +56,7 @@
5756
"@types/react": "^17.0.28",
5857
"@typescript-eslint/eslint-plugin": "^5.0.0",
5958
"@typescript-eslint/parser": "^5.0.0",
60-
"babel-eslint": "^10.0.3",
59+
"browserslist": "^4.17.3",
6160
"chart.js": "^3.1.0",
6261
"clean-publish": "^3.4.1",
6362
"eslint": "^7.32.0",
@@ -73,11 +72,12 @@
7372
"jest": "^27.2.5",
7473
"jest-canvas-mock": "^2.2.0",
7574
"lint-staged": "^11.2.3",
76-
"microbundle-crl": "^0.13.11",
7775
"prettier": "^2.0.4",
7876
"react": "^17.0.1",
7977
"react-dom": "^17.0.1",
8078
"react-test-renderer": "^17.0.1",
79+
"rollup": "^2.58.0",
80+
"rollup-plugin-swc": "^0.2.0",
8181
"simple-git-hooks": "^2.6.1",
8282
"size-limit": "^6.0.3",
8383
"typescript": "^4.4.3"

rollup.config.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import swc from 'rollup-plugin-swc';
2+
import { nodeResolve } from '@rollup/plugin-node-resolve';
3+
import pkg from './package.json';
4+
5+
const extensions = ['.js', '.ts', '.tsx'];
6+
const external = _ => /node_modules/.test(_) && !/@swc\/helpers/.test(_);
7+
const plugins = [
8+
nodeResolve({
9+
extensions,
10+
}),
11+
swc({
12+
jsc: {
13+
parser: {
14+
syntax: 'typescript',
15+
tsx: true,
16+
},
17+
transform: {
18+
react: {
19+
useBuiltins: true,
20+
},
21+
},
22+
externalHelpers: true,
23+
},
24+
env: {
25+
targets: 'defaults',
26+
},
27+
module: {
28+
type: 'es6',
29+
},
30+
sourceMaps: true,
31+
}),
32+
];
33+
34+
export default [
35+
{
36+
input: 'src/index.tsx',
37+
plugins,
38+
external,
39+
output: {
40+
file: pkg.main,
41+
format: 'cjs',
42+
exports: 'named',
43+
sourcemap: true,
44+
},
45+
},
46+
{
47+
input: 'src/index.tsx',
48+
plugins,
49+
external,
50+
output: {
51+
file: pkg.module,
52+
format: 'es',
53+
sourcemap: true,
54+
},
55+
},
56+
];

tsconfig.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@
1616
"noUnusedLocals": true,
1717
"noUnusedParameters": true,
1818
"allowSyntheticDefaultImports": true,
19-
"target": "es5",
19+
"target": "esnext",
2020
"allowJs": true,
2121
"skipLibCheck": true,
2222
"strict": true,
2323
"forceConsistentCasingInFileNames": true,
2424
"resolveJsonModule": true,
25-
"isolatedModules": true,
26-
"noEmit": true
25+
"isolatedModules": true
2726
},
2827
"include": ["src"],
2928
"exclude": ["node_modules", "dist", "example"]

0 commit comments

Comments
 (0)