Skip to content

Commit

Permalink
(types/fix): explicit Rollup typing, fix treeshake location (#371)
Browse files Browse the repository at this point in the history
- treeshake was in output, but it's not a config of output :/ :/ :/
  - once explicit types were added, this was a big red underline :/ :/
  • Loading branch information
agilgur5 authored and jaredpalmer committed Dec 19, 2019
1 parent ee4b307 commit 2a5e5a5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
47 changes: 25 additions & 22 deletions src/createRollupConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
resolveApp,
} from './utils';
import { paths } from './constants';
import { RollupOptions } from 'rollup';
import { terser } from 'rollup-plugin-terser';
import { DEFAULT_EXTENSIONS } from '@babel/core';
// import babel from 'rollup-plugin-babel';
Expand All @@ -26,7 +27,9 @@ const errorCodeOpts = {
// shebang cache map thing because the transform only gets run once
let shebang: any = {};

export async function createRollupConfig(opts: TsdxOptions) {
export async function createRollupConfig(
opts: TsdxOptions
): Promise<RollupOptions> {
const findAndRecordErrorCodes = await extractErrors({
...errorCodeOpts,
...opts,
Expand Down Expand Up @@ -60,6 +63,27 @@ export async function createRollupConfig(opts: TsdxOptions) {
}
return external(id);
},
// Rollup has treeshaking by default, but we can optimize it further...
treeshake: {
// We assume reading a property of an object never has side-effects.
// This means tsdx WILL remove getters and setters defined directly on objects.
// Any getters or setters defined on classes will not be effected.
//
// @example
//
// const foo = {
// get bar() {
// console.log('effect');
// return 'bar';
// }
// }
//
// const result = foo.bar;
// const illegalAccess = foo.quux.tooDeep;
//
// Punchline....Don't use getters and setters
propertyReadSideEffects: false,
},
// Establish Rollup output
output: {
// Set filenames of the consumer's package
Expand All @@ -71,27 +95,6 @@ export async function createRollupConfig(opts: TsdxOptions) {
freeze: false,
// Respect tsconfig esModuleInterop when setting __esModule.
esModule: tsconfigJSON ? tsconfigJSON.esModuleInterop : false,
// Rollup has treeshaking by default, but we can optimize it further...
treeshake: {
// We assume reading a property of an object never has side-effects.
// This means tsdx WILL remove getters and setters defined directly on objects.
// Any getters or setters defined on classes will not be effected.
//
// @example
//
// const foo = {
// get bar() {
// console.log('effect');
// return 'bar';
// }
// }
//
// const result = foo.bar;
// const illegalAccess = foo.quux.tooDeep;
//
// Punchline....Don't use getters and setters
propertyReadSideEffects: false,
},
name: opts.name || safeVariableName(opts.name),
sourcemap: true,
globals: { react: 'React', 'react-native': 'ReactNative' },
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ try {

// check for custom tsdx.config.js
let tsdxConfig = {
rollup(config: any, _options: any) {
rollup(config: RollupOptions, _options: TsdxOptions): RollupOptions {
return config;
},
};
Expand Down

0 comments on commit 2a5e5a5

Please sign in to comment.