1+ import dts from 'rollup-plugin-dts'
2+ import esbuild from 'rollup-plugin-esbuild'
13import typescript from "rollup-plugin-typescript2"
24import commonjs from "rollup-plugin-commonjs"
35import external from "rollup-plugin-peer-deps-external"
46import resolve from "rollup-plugin-node-resolve"
57import postcss from "rollup-plugin-postcss"
68import { terser } from "rollup-plugin-terser"
79
8- import pkg from " ./package.json"
10+ const name = require ( ' ./package.json' ) . main . replace ( / \. j s $ / , '' )
911
10- export default {
11- input : "src/index.ts" ,
12- output : [
13- {
14- file : pkg . main ,
15- format : "cjs" ,
16- exports : "named" ,
17- sourcemap : true ,
18- } ,
19- {
20- file : pkg . module ,
21- format : "es" ,
22- exports : "named" ,
23- sourcemap : true ,
24- } ,
25- ] ,
26- plugins : [
27- resolve ( ) ,
28- postcss ( {
29- extensions : [ ".css" ] ,
30- extract : true ,
31- } ) ,
32- external ( ) ,
33- typescript ( {
34- rollupCommonJSResolveHack : true ,
35- exclude : [ "**/__tests__/**" , "**/*.stories.tsx" ] ,
36- clean : true ,
37- } ) ,
38- terser ( ) ,
39- commonjs ( {
40- include : [ "node_modules/**" ] ,
41- namedExports : {
42- "node_modules/react/react.js" : [
43- "Children" ,
44- "Component" ,
45- "PropTypes" ,
46- "createElement" ,
47- ] ,
48- "node_modules/react-dom/index.js" : [ "render" ] ,
12+ const bundle = config => ( {
13+ ...config ,
14+ input : 'src/index.ts' ,
15+ external : id => ! / ^ [ . / ] / . test ( id ) ,
16+ } )
17+
18+ export default [
19+ bundle ( {
20+ plugins : [ esbuild ( ) ] ,
21+ output : [
22+ {
23+ file : `${ name } .js` ,
24+ format : 'cjs' ,
25+ sourcemap : true ,
4926 } ,
50- } ) ,
51- ] ,
52- }
27+ {
28+ file : `${ name } .mjs` ,
29+ format : 'es' ,
30+ sourcemap : true ,
31+ } ,
32+ ] ,
33+ } ) ,
34+ bundle ( {
35+ plugins : [ dts ( ) ] ,
36+ output : {
37+ file : `${ name } .d.ts` ,
38+ format : 'es' ,
39+ } ,
40+ } ) ,
41+ bundle ( {
42+ plugins : [ ,
43+ resolve ( ) ,
44+ postcss ( {
45+ extensions : [ ".css" ] ,
46+ extract : true ,
47+ } ) ,
48+ external ( ) ,
49+ typescript ( {
50+ rollupCommonJSResolveHack : true ,
51+ exclude : [ "**/__tests__/**" , "**/*.stories.tsx" ] ,
52+ clean : true ,
53+ } ) ,
54+ terser ( ) ,
55+ commonjs ( {
56+ include : [ "node_modules/**" ] ,
57+ namedExports : {
58+ "node_modules/react/react.js" : [
59+ "Children" ,
60+ "Component" ,
61+ "PropTypes" ,
62+ "createElement" ,
63+ ] ,
64+ "node_modules/react-dom/index.js" : [ "render" ] ,
65+ } ,
66+ } ) ,
67+ ]
68+ } )
69+ ]
0 commit comments