Skip to content

Commit 82fc82c

Browse files
committed
build: avoid using jsx-runtime
1 parent 691b8b6 commit 82fc82c

File tree

8 files changed

+31
-63
lines changed

8 files changed

+31
-63
lines changed

rollup.config.prod.js

+23-56
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ const input = ['src/index.tsx']
1414
const name = 'ReactTooltip'
1515

1616
const external = [
17-
...Object.keys({ ...(pkg.peerDependencies ?? {}), ...(pkg.dependencies ?? {}) }),
18-
'react/jsx-runtime',
17+
...Object.keys(pkg.peerDependencies ?? {}),
18+
...Object.keys(pkg.dependencies ?? {}),
1919
]
2020

2121
const buildFormats = [
2222
{
2323
file: 'dist/react-tooltip.umd.js',
2424
format: 'umd',
2525
globals: {
26+
'@floating-ui/dom': 'FloatingUIDOM',
2627
react: 'React',
2728
'react-dom': 'ReactDOM',
2829
classnames: 'classNames',
@@ -39,19 +40,22 @@ const buildFormats = [
3940
},
4041
]
4142

42-
// splitted to be reusable by minified css build and unminified css
43-
const pluginsBeforePostCSS = [
43+
const sharedPlugins = [
4444
progress(),
4545
replace({
4646
preventAssignment: true,
4747
values: {
4848
'process.env.NODE_ENV': JSON.stringify('development'),
4949
},
5050
}),
51-
]
52-
53-
// splitted to be reusable by minified css build and unminified css
54-
const pluginsAfterPostCSS = [
51+
postcss({
52+
extract: 'react-tooltip.min.css', // this will generate a specific file and override on multiples build, but the css will be the same
53+
autoModules: true,
54+
include: '**/*.css',
55+
extensions: ['.css'],
56+
plugins: [],
57+
minimize: true,
58+
}),
5559
nodeResolve(),
5660
ts({
5761
typescript,
@@ -64,61 +68,24 @@ const pluginsAfterPostCSS = [
6468
include: 'node_modules/**',
6569
}),
6670
]
67-
68-
const plugins = [
69-
...pluginsBeforePostCSS,
70-
postcss({
71-
// extract: true, // this will generate a css file based on output file name
72-
extract: 'react-tooltip.css', // this will generate a specific file and override on multiples build, but the css will be the same
73-
autoModules: true,
74-
include: '**/*.css',
75-
extensions: ['.css'],
76-
plugins: [],
77-
}),
78-
...pluginsAfterPostCSS,
79-
]
80-
81-
const pluginsForCSSMinification = [
82-
...pluginsBeforePostCSS,
83-
postcss({
84-
extract: 'react-tooltip.min.css', // this will generate a specific file and override on multiples build, but the css will be the same
85-
autoModules: true,
86-
include: '**/*.css',
87-
extensions: ['.css'],
88-
plugins: [],
89-
minimize: true,
90-
}),
91-
...pluginsAfterPostCSS,
92-
]
93-
94-
const defaultOutputData = buildFormats.map(({ file, format, globals }) => ({
95-
file,
96-
format,
97-
plugins: [...plugins, filesize()],
98-
globals,
99-
}))
100-
10171
// this step is just to build the minified css and es modules javascript
102-
const minifiedOutputData = buildFormats.map(({ file, format, globals }) => ({
103-
file: file.replace('.js', '.min.js').replace('.cjs', '.min.cjs').replace('.mjs', '.min.mjs'),
104-
format,
105-
plugins: [...pluginsForCSSMinification, terser(), filesize()],
106-
globals,
72+
const minifiedBuildFormats = buildFormats.map(({ file, ...rest }) => ({
73+
file: file.replace(/(\.[cm]?js)$/, '.min$1'),
74+
...rest,
75+
plugins: [terser(), filesize()],
10776
}))
10877

109-
const outputData = [...defaultOutputData, ...minifiedOutputData]
78+
const allBuildFormats = [...buildFormats, ...minifiedBuildFormats]
11079

111-
const config = outputData.map(({ file, format, plugins: specificPLugins, globals }) => ({
80+
const config = {
11281
input,
113-
output: {
114-
file,
115-
format,
82+
output: allBuildFormats.map((buildFormat) => ({
11683
name,
117-
globals,
84+
...buildFormat,
11885
sourcemap: true,
119-
},
86+
})),
12087
external,
121-
plugins: specificPLugins,
122-
}))
88+
plugins: sharedPlugins,
89+
}
12390

12491
export default config

src/App.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* eslint-disable jsx-a11y/click-events-have-key-events */
33
import { TooltipController as Tooltip } from 'components/TooltipController'
44
import { IPosition } from 'components/Tooltip/TooltipTypes.d'
5-
import { useState } from 'react'
5+
import React, { useState } from 'react'
66
import { inline, offset } from '@floating-ui/dom'
77
import styles from './styles.module.css'
88

src/components/Tooltip/Tooltip.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useState, useRef } from 'react'
1+
import React, { useEffect, useState, useRef } from 'react'
22
import classNames from 'classnames'
33
import debounce from 'utils/debounce'
44
import { useTooltip } from 'components/TooltipProvider'

src/components/TooltipContent/TooltipContent.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-disable react/no-danger */
2+
import React from 'react'
23
import type { ITooltipContent } from './TooltipContentTypes'
34

45
const TooltipContent = ({ content }: ITooltipContent) => {

src/components/TooltipController/TooltipController.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useState } from 'react'
1+
import React, { useEffect, useState } from 'react'
22
import { Tooltip } from 'components/Tooltip'
33
import type {
44
EventsType,

src/components/TooltipProvider/TooltipWrapper.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useRef } from 'react'
1+
import React, { useEffect, useRef } from 'react'
22
import classNames from 'classnames'
33
import { useTooltip } from './TooltipProvider'
44
import type { ITooltipWrapper } from './TooltipProviderTypes'

src/index-dev-react-18.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { StrictMode, version } from 'react'
1+
import React, { StrictMode, version } from 'react'
22
// eslint-disable-next-line import/no-unresolved
33
import { createRoot } from 'react-dom/client' // this is we are now using react < 18
44
import './tokens.css'

tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
"DOM",
2020
"DOM.iterable"
2121
] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
22-
"jsx": "react-jsx" /* Specify what JSX code is generated. */,
22+
"jsx": "react" /* Specify what JSX code is generated. */,
2323
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
2424
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
2525
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
2626
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
27-
"jsxImportSource": "react", /* 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*'. */
2828
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
2929
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
3030
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */

0 commit comments

Comments
 (0)