1- import path from 'path' ;
2- import resolvePlugin from '@rollup/plugin-node-resolve' ;
3- import babelPlugin from 'rollup-plugin-babel' ;
4- import externalsPlugin from 'rollup-plugin-auto-external' ;
1+ const path = require ( 'path' ) ;
2+ const replacePlugin = require ( 'rollup-plugin-replace' ) ;
3+ const resolvePlugin = require ( '@rollup/plugin-node-resolve' ) ;
4+ const babelPlugin = require ( 'rollup-plugin-babel' ) ;
5+ const externalsPlugin = require ( 'rollup-plugin-auto-external' ) ;
56
6- export default [
7+ // this is also used in watch mode by the startExample script
8+ const defaultBuild = [
9+ {
10+ input : path . resolve ( 'src/platforms/dom.js' ) ,
11+ external : [ 'react-dom' ] ,
12+ output : [
13+ {
14+ format : 'es' ,
15+ dir : 'dist' ,
16+ entryFileNames : 'react-platform.js' ,
17+ } ,
18+ {
19+ format : 'cjs' ,
20+ dir : 'dist' ,
21+ entryFileNames : 'react-platform.cjs.js' ,
22+ } ,
23+ ] ,
24+ } ,
725 {
826 input : path . resolve ( 'src/index.js' ) ,
27+ external : [ './react-platform' ] ,
928 plugins : [
29+ replacePlugin ( { 'react-platform' : './react-platform' } ) ,
1030 resolvePlugin ( ) ,
1131 babelPlugin ( { exclude : 'node_modules/**' } ) ,
1232 externalsPlugin ( { dependencies : true , peerDependecies : true } ) ,
@@ -18,9 +38,31 @@ export default [
1838 sourcemap : true ,
1939 } ,
2040 } ,
41+ ] ;
42+
43+ const allBuilds = [
44+ ...defaultBuild ,
45+ {
46+ input : path . resolve ( 'src/platforms/native.js' ) ,
47+ external : [ 'react-native' ] ,
48+ output : [
49+ {
50+ format : 'es' ,
51+ dir : 'dist' ,
52+ entryFileNames : 'react-platform.native.js' ,
53+ } ,
54+ {
55+ format : 'cjs' ,
56+ dir : 'dist' ,
57+ entryFileNames : 'react-platform.cjs.native.js' ,
58+ } ,
59+ ] ,
60+ } ,
2161 {
2262 input : path . resolve ( 'src/index.js' ) ,
63+ external : [ './react-platform' ] ,
2364 plugins : [
65+ replacePlugin ( { 'react-platform' : './react-platform' } ) ,
2466 resolvePlugin ( ) ,
2567 babelPlugin ( {
2668 exclude : 'node_modules/**' ,
@@ -37,7 +79,9 @@ export default [
3779 } ,
3880 {
3981 input : path . resolve ( 'src/index.js' ) ,
82+ external : [ './react-platform.cjs' ] ,
4083 plugins : [
84+ replacePlugin ( { 'react-platform' : './react-platform.cjs' } ) ,
4185 resolvePlugin ( ) ,
4286 babelPlugin ( { exclude : 'node_modules/**' } ) ,
4387 externalsPlugin ( { dependencies : true , peerDependecies : true } ) ,
@@ -51,7 +95,9 @@ export default [
5195 } ,
5296 {
5397 input : path . resolve ( 'src/index.js' ) ,
98+ external : [ './react-platform.cjs' ] ,
5499 plugins : [
100+ replacePlugin ( { 'react-platform' : './react-platform.cjs' } ) ,
55101 resolvePlugin ( ) ,
56102 babelPlugin ( {
57103 exclude : 'node_modules/**' ,
@@ -67,3 +113,9 @@ export default [
67113 } ,
68114 } ,
69115] ;
116+
117+ module . exports = {
118+ defaultBuild,
119+ // this has to be exported as default for rollup CLI to pick it up
120+ default : allBuilds ,
121+ } ;
0 commit comments