Skip to content

fix: package export files #1005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/bundlesize.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
run: yarn install

- name: Build ReactTooltip component package
run: yarn build-rollup
run: yarn build

- name: Bundlesize
run: yarn run bundlesize
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"description": "react tooltip component",
"scripts": {
"dev-rollup": "node ./prebuild.js --env=development && node --max_old_space_size=2048 ./node_modules/rollup/dist/bin/rollup -c rollup.config.dev.js --watch",
"build-rollup": "node ./prebuild.js --env=production && npm run types && node --max_old_space_size=2048 ./node_modules/rollup/dist/bin/rollup -c rollup.config.prod.js",
"build": "node ./prebuild.js --env=production && npm run types && node --max_old_space_size=2048 ./node_modules/rollup/dist/bin/rollup -c rollup.config.prod.js",
"dev": "node ./prebuild.js --env=development && node ./esbuild.config.dev.mjs",
"build": "node ./prebuild.js --env=production && node ./esbuild.config.prod.mjs",
"build-eslint": "node ./prebuild.js --env=production && node ./esbuild.config.prod.mjs",
"types": "node --max_old_space_size=2048 ./node_modules/rollup/dist/bin/rollup -c rollup.config.types.js",
"eslint": "eslint --ext=js --ext=jsx --ext=ts --ext=tsx --fix ./src",
"stylelint": "stylelint \"src/**/*.css\"",
Expand All @@ -16,7 +16,7 @@
"esbuild": "esbuild",
"test": "jest",
"postbuild": "npm run types && npm run bundlesize",
"prepublishOnly": "npm run build-rollup"
"prepublishOnly": "npm run build"
},
"types": "dist/react-tooltip.d.ts",
"license": "MIT",
Expand All @@ -32,13 +32,16 @@
"bugs": {
"url": "https://github.com/ReactTooltip/react-tooltip/issues"
},
"main": "dist/react-tooltip.min.cjs",
"module": "dist/react-tooltip.min.mjs",
"exports": {
".": {
"types": "./dist/react-tooltip.d.ts",
"require": "./dist/react-tooltip.min.cjs",
"import": "./dist/react-tooltip.min.mjs",
"default": "./dist/react-tooltip.min.cjs"
},
"./dist/react-tooltip": "./dist/react-tooltip.min.cjs",
"./dist/react-tooltip.css": "./dist/react-tooltip.min.css",
"./dist/react-tooltip.d.ts": "./dist/react-tooltip.d.ts",
"./package.json": "./package.json"
Expand Down
53 changes: 34 additions & 19 deletions rollup.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@ const sharedPlugins = [
'process.env.NODE_ENV': JSON.stringify('development'),
},
}),
postcss({
extract: 'react-tooltip.min.css', // this will generate a specific file and override on multiples build, but the css will be the same
autoModules: true,
include: '**/*.css',
extensions: ['.css'],
plugins: [],
minimize: true,
}),
nodeResolve(),
ts({
typescript,
Expand All @@ -68,24 +60,47 @@ const sharedPlugins = [
include: 'node_modules/**',
}),
]
// this step is just to build the minified css and es modules javascript
// this step is just to build the minified javascript files
const minifiedBuildFormats = buildFormats.map(({ file, ...rest }) => ({
file: file.replace(/(\.[cm]?js)$/, '.min$1'),
...rest,
minify: true,
plugins: [terser(), filesize()],
}))

const allBuildFormats = [...buildFormats, ...minifiedBuildFormats]

const config = {
input,
output: allBuildFormats.map((buildFormat) => ({
name,
...buildFormat,
sourcemap: true,
})),
external,
plugins: sharedPlugins,
}
const config = allBuildFormats.map(
({ file, format, globals, plugins: specificPlugins, minify }) => {
const plugins = [
...sharedPlugins,
postcss({
extract: minify ? 'react-tooltip.min.css' : 'react-tooltip.css', // this will generate a specific file and override on multiples build, but the css will be the same
autoModules: true,
include: '**/*.css',
extensions: ['.css'],
plugins: [],
minimize: Boolean(minify),
}),
]

if (specificPlugins && specificPlugins.length) {
plugins.push(...specificPlugins)
}

return {
input,
output: {
file,
format,
name,
globals,
sourcemap: true,
},
external,
plugins,
}
},
)

export default config