-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: ♻️ convert package to typescript
- Loading branch information
1 parent
1b5b61d
commit 89e23d3
Showing
11 changed files
with
674 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import typescript from '@rollup/plugin-typescript' | ||
import replace from '@rollup/plugin-replace' | ||
import fs from 'fs' | ||
|
||
const defaultOptions = () => ({ | ||
// additional variables to define with '@rollup/plugin-replace' | ||
// e.g. '{ ABC: 123 }' is equivalent to running 'globalThis.ABC = 123' | ||
additionalReplacements: {}, | ||
// additional external dependencies, such as '@bugsnag/browser' | ||
external: [], | ||
// the entry point for the bundle | ||
internal: undefined, | ||
}) | ||
|
||
function createRollupConfig (options = defaultOptions()) { | ||
const packageJson = JSON.parse(fs.readFileSync(`${process.cwd()}/package.json`)) | ||
|
||
return { | ||
input: options.internal || 'lib/index.ts', | ||
output: { | ||
dir: 'dist', | ||
format: 'esm', | ||
preserveModules: true, | ||
generatedCode: { | ||
preset: 'es2015', | ||
}, | ||
}, | ||
external: ['@bugsnag/core'].concat(options.external), | ||
plugins: [ | ||
replace({ | ||
preventAssignment: true, | ||
values: { | ||
__VERSION__: packageJson.version, | ||
...options.additionalReplacements, | ||
}, | ||
}), | ||
typescript({ | ||
// don't output anything if there's a TS error | ||
noEmitOnError: true, | ||
// turn on declaration files and declaration maps | ||
compilerOptions: { | ||
declaration: true, | ||
declarationMap: true, | ||
emitDeclarationOnly: true, | ||
declarationDir: 'dist/types', | ||
}, | ||
}), | ||
], | ||
} | ||
} | ||
|
||
export default createRollupConfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// when functional components are used in JSX tags, rollup doesn't recognise them as actually being used and tree-shakes them away | ||
// this plugin prevents that from happening by explicity telling rollup not to tree-shake the module | ||
function noTreeShakingPlugin(files) { | ||
return { | ||
name: 'no-treeshaking-plugin', | ||
transform(code, id) { | ||
for (const file of files) { | ||
if (id.indexOf(file) >= 0) { | ||
return { moduleSideEffects: 'no-treeshake' } | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
export default noTreeShakingPlugin |
Oops, something went wrong.