5
5
resolveApp ,
6
6
} from './utils' ;
7
7
import { paths } from './constants' ;
8
+ import { RollupOptions } from 'rollup' ;
8
9
import { terser } from 'rollup-plugin-terser' ;
9
10
import { DEFAULT_EXTENSIONS } from '@babel/core' ;
10
11
// import babel from 'rollup-plugin-babel';
@@ -26,7 +27,9 @@ const errorCodeOpts = {
26
27
// shebang cache map thing because the transform only gets run once
27
28
let shebang : any = { } ;
28
29
29
- export async function createRollupConfig ( opts : TsdxOptions ) {
30
+ export async function createRollupConfig (
31
+ opts : TsdxOptions
32
+ ) : Promise < RollupOptions > {
30
33
const findAndRecordErrorCodes = await extractErrors ( {
31
34
...errorCodeOpts ,
32
35
...opts ,
@@ -60,6 +63,27 @@ export async function createRollupConfig(opts: TsdxOptions) {
60
63
}
61
64
return external ( id ) ;
62
65
} ,
66
+ // Rollup has treeshaking by default, but we can optimize it further...
67
+ treeshake : {
68
+ // We assume reading a property of an object never has side-effects.
69
+ // This means tsdx WILL remove getters and setters defined directly on objects.
70
+ // Any getters or setters defined on classes will not be effected.
71
+ //
72
+ // @example
73
+ //
74
+ // const foo = {
75
+ // get bar() {
76
+ // console.log('effect');
77
+ // return 'bar';
78
+ // }
79
+ // }
80
+ //
81
+ // const result = foo.bar;
82
+ // const illegalAccess = foo.quux.tooDeep;
83
+ //
84
+ // Punchline....Don't use getters and setters
85
+ propertyReadSideEffects : false ,
86
+ } ,
63
87
// Establish Rollup output
64
88
output : {
65
89
// Set filenames of the consumer's package
@@ -71,27 +95,6 @@ export async function createRollupConfig(opts: TsdxOptions) {
71
95
freeze : false ,
72
96
// Respect tsconfig esModuleInterop when setting __esModule.
73
97
esModule : tsconfigJSON ? tsconfigJSON . esModuleInterop : false ,
74
- // Rollup has treeshaking by default, but we can optimize it further...
75
- treeshake : {
76
- // We assume reading a property of an object never has side-effects.
77
- // This means tsdx WILL remove getters and setters defined directly on objects.
78
- // Any getters or setters defined on classes will not be effected.
79
- //
80
- // @example
81
- //
82
- // const foo = {
83
- // get bar() {
84
- // console.log('effect');
85
- // return 'bar';
86
- // }
87
- // }
88
- //
89
- // const result = foo.bar;
90
- // const illegalAccess = foo.quux.tooDeep;
91
- //
92
- // Punchline....Don't use getters and setters
93
- propertyReadSideEffects : false ,
94
- } ,
95
98
name : opts . name || safeVariableName ( opts . name ) ,
96
99
sourcemap : true ,
97
100
globals : { react : 'React' , 'react-native' : 'ReactNative' } ,
0 commit comments