Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(types/fix): explicit Rollup typing, fix treeshake location #371

Merged
merged 1 commit into from
Dec 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -47,7 +47,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