Skip to content

Commit 9237e9e

Browse files
committed
feat: change the build to auto inject css into the page
1 parent 7de068a commit 9237e9e

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

rollup.config.prod.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ const external = [
1919
]
2020

2121
const buildFormats = [
22+
/**
23+
* Temporary build to keep the extracted CSS file.
24+
* I don't want to do a major release now with only the CSS change,
25+
* so, we will keep the css being exported by the lib and now
26+
* we will inject the css into the head by default.
27+
* The CSS file import is deprecated and the file is only
28+
* for style reference now.
29+
*/
30+
{
31+
file: 'dist/react-tooltip.mjs',
32+
format: 'es',
33+
extractCSS: true,
34+
},
2235
{
2336
file: 'dist/react-tooltip.umd.js',
2437
format: 'umd',
@@ -61,21 +74,23 @@ const sharedPlugins = [
6174
}),
6275
]
6376
// this step is just to build the minified javascript files
64-
const minifiedBuildFormats = buildFormats.map(({ file, ...rest }) => ({
77+
const minifiedBuildFormats = buildFormats.map(({ file, extractCSS, ...rest }) => ({
6578
file: file.replace(/(\.[cm]?js)$/, '.min$1'),
6679
...rest,
6780
minify: true,
81+
extractCSS,
6882
plugins: [terser(), filesize()],
6983
}))
7084

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

7387
const config = allBuildFormats.map(
74-
({ file, format, globals, plugins: specificPlugins, minify }) => {
88+
({ file, format, globals, plugins: specificPlugins, minify, extractCSS }) => {
7589
const plugins = [
7690
...sharedPlugins,
7791
postcss({
78-
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
92+
// eslint-disable-next-line no-nested-ternary
93+
extract: extractCSS ? (minify ? 'react-tooltip.min.css' : 'react-tooltip.css') : false, // this will generate a specific file and override on multiples build, but the css will be the same
7994
autoModules: true,
8095
include: '**/*.css',
8196
extensions: ['.css'],

0 commit comments

Comments
 (0)