Skip to content

Commit

Permalink
build: install missing dep, fix ts config, make dependencies external
Browse files Browse the repository at this point in the history
  • Loading branch information
GerkinDev committed Mar 15, 2023
1 parent 2f69691 commit 194d2ab
Show file tree
Hide file tree
Showing 4 changed files with 802 additions and 973 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@types/css": "^0.0.33",
"@types/css-modules": "^1.0.2",
"@types/jest": "29.4.0",
"@types/node": "^18.15.3",
"@types/react": "18.0.28",
"@types/react-dom": "18.0.11",
"@types/react-test-renderer": "^18.0.0",
Expand Down
29 changes: 18 additions & 11 deletions rollup.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,27 @@ import { nodeResolve } from '@rollup/plugin-node-resolve'
import ts from '@rollup/plugin-typescript'
import { terser } from 'rollup-plugin-terser'
import typescript from 'typescript'
import * as pkg from './package.json'

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

const name = 'ReactTooltip'

const external = ['react', 'react-dom', 'prop-types']

const globals = {
react: 'React',
'react-dom': 'ReactDOM',
classnames: 'classNames',
'prop-types': 'PropTypes',
}
const external = [
...Object.keys({ ...(pkg.peerDependencies ?? {}), ...(pkg.dependencies ?? {}) }),
'react/jsx-runtime'
];

const buildFormats = [
{
file: 'dist/react-tooltip.umd.js',
format: 'umd',
globals: {
react: 'React',
'react-dom': 'ReactDOM',
classnames: 'classNames',
'prop-types': 'PropTypes',
},
},
{
file: 'dist/react-tooltip.cjs.js',
Expand Down Expand Up @@ -88,22 +91,24 @@ const pluginsForCSSMinification = [
...pluginsAfterPostCSS,
]

const defaultOutputData = buildFormats.map(({ file, format }) => ({
const defaultOutputData = buildFormats.map(({ file, format, globals }) => ({
file,
format,
plugins: [...plugins, filesize()],
globals,
}))

// this step is just to build the minified css and es modules javascript
const minifiedOutputData = buildFormats.map(({ file, format }) => ({
const minifiedOutputData = buildFormats.map(({ file, format, globals }) => ({
file: file.replace('.js', '.min.js'),
format,
plugins: [...pluginsForCSSMinification, terser(), filesize()],
globals,
}))

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

const config = outputData.map(({ file, format, plugins: specificPLugins }) => ({
const config = outputData.map(({ file, format, plugins: specificPLugins, globals }) => ({
input,
output: {
file,
Expand All @@ -115,4 +120,6 @@ const config = outputData.map(({ file, format, plugins: specificPLugins }) => ({
plugins: specificPLugins,
}))

console.log(config)

export default config
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
"target": "es2018" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
"lib": [
"es2018",
"DOM"
"DOM",
"DOM.iterable"
] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
"jsx": "react-jsx" /* Specify what JSX code is generated. */,
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
"jsxImportSource": "react", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
Expand Down
Loading

0 comments on commit 194d2ab

Please sign in to comment.