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' ) ;
5
6
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
+ } ,
7
25
{
8
26
input : path . resolve ( 'src/index.js' ) ,
27
+ external : [ './react-platform' ] ,
9
28
plugins : [
29
+ replacePlugin ( { 'react-platform' : './react-platform' } ) ,
10
30
resolvePlugin ( ) ,
11
31
babelPlugin ( { exclude : 'node_modules/**' } ) ,
12
32
externalsPlugin ( { dependencies : true , peerDependecies : true } ) ,
@@ -18,9 +38,31 @@ export default [
18
38
sourcemap : true ,
19
39
} ,
20
40
} ,
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
+ } ,
21
61
{
22
62
input : path . resolve ( 'src/index.js' ) ,
63
+ external : [ './react-platform' ] ,
23
64
plugins : [
65
+ replacePlugin ( { 'react-platform' : './react-platform' } ) ,
24
66
resolvePlugin ( ) ,
25
67
babelPlugin ( {
26
68
exclude : 'node_modules/**' ,
@@ -37,7 +79,9 @@ export default [
37
79
} ,
38
80
{
39
81
input : path . resolve ( 'src/index.js' ) ,
82
+ external : [ './react-platform.cjs' ] ,
40
83
plugins : [
84
+ replacePlugin ( { 'react-platform' : './react-platform.cjs' } ) ,
41
85
resolvePlugin ( ) ,
42
86
babelPlugin ( { exclude : 'node_modules/**' } ) ,
43
87
externalsPlugin ( { dependencies : true , peerDependecies : true } ) ,
@@ -51,7 +95,9 @@ export default [
51
95
} ,
52
96
{
53
97
input : path . resolve ( 'src/index.js' ) ,
98
+ external : [ './react-platform.cjs' ] ,
54
99
plugins : [
100
+ replacePlugin ( { 'react-platform' : './react-platform.cjs' } ) ,
55
101
resolvePlugin ( ) ,
56
102
babelPlugin ( {
57
103
exclude : 'node_modules/**' ,
@@ -67,3 +113,9 @@ export default [
67
113
} ,
68
114
} ,
69
115
] ;
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