Skip to content

Commit 194d2ab

Browse files
committed
build: install missing dep, fix ts config, make dependencies external
1 parent 2f69691 commit 194d2ab

File tree

4 files changed

+802
-973
lines changed

4 files changed

+802
-973
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"@types/css": "^0.0.33",
4747
"@types/css-modules": "^1.0.2",
4848
"@types/jest": "29.4.0",
49+
"@types/node": "^18.15.3",
4950
"@types/react": "18.0.28",
5051
"@types/react-dom": "18.0.11",
5152
"@types/react-test-renderer": "^18.0.0",

rollup.config.prod.js

+18-11
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,27 @@ import { nodeResolve } from '@rollup/plugin-node-resolve'
77
import ts from '@rollup/plugin-typescript'
88
import { terser } from 'rollup-plugin-terser'
99
import typescript from 'typescript'
10+
import * as pkg from './package.json'
1011

1112
const input = ['src/index.tsx']
1213

1314
const name = 'ReactTooltip'
1415

15-
const external = ['react', 'react-dom', 'prop-types']
16-
17-
const globals = {
18-
react: 'React',
19-
'react-dom': 'ReactDOM',
20-
classnames: 'classNames',
21-
'prop-types': 'PropTypes',
22-
}
16+
const external = [
17+
...Object.keys({ ...(pkg.peerDependencies ?? {}), ...(pkg.dependencies ?? {}) }),
18+
'react/jsx-runtime'
19+
];
2320

2421
const buildFormats = [
2522
{
2623
file: 'dist/react-tooltip.umd.js',
2724
format: 'umd',
25+
globals: {
26+
react: 'React',
27+
'react-dom': 'ReactDOM',
28+
classnames: 'classNames',
29+
'prop-types': 'PropTypes',
30+
},
2831
},
2932
{
3033
file: 'dist/react-tooltip.cjs.js',
@@ -88,22 +91,24 @@ const pluginsForCSSMinification = [
8891
...pluginsAfterPostCSS,
8992
]
9093

91-
const defaultOutputData = buildFormats.map(({ file, format }) => ({
94+
const defaultOutputData = buildFormats.map(({ file, format, globals }) => ({
9295
file,
9396
format,
9497
plugins: [...plugins, filesize()],
98+
globals,
9599
}))
96100

97101
// this step is just to build the minified css and es modules javascript
98-
const minifiedOutputData = buildFormats.map(({ file, format }) => ({
102+
const minifiedOutputData = buildFormats.map(({ file, format, globals }) => ({
99103
file: file.replace('.js', '.min.js'),
100104
format,
101105
plugins: [...pluginsForCSSMinification, terser(), filesize()],
106+
globals,
102107
}))
103108

104109
const outputData = [...defaultOutputData, ...minifiedOutputData]
105110

106-
const config = outputData.map(({ file, format, plugins: specificPLugins }) => ({
111+
const config = outputData.map(({ file, format, plugins: specificPLugins, globals }) => ({
107112
input,
108113
output: {
109114
file,
@@ -115,4 +120,6 @@ const config = outputData.map(({ file, format, plugins: specificPLugins }) => ({
115120
plugins: specificPLugins,
116121
}))
117122

123+
console.log(config)
124+
118125
export default config

tsconfig.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
"target": "es2018" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
1717
"lib": [
1818
"es2018",
19-
"DOM"
19+
"DOM",
20+
"DOM.iterable"
2021
] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
2122
"jsx": "react-jsx" /* Specify what JSX code is generated. */,
2223
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
2324
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
2425
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
2526
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
26-
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
27+
"jsxImportSource": "react", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
2728
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
2829
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
2930
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */

0 commit comments

Comments
 (0)