Skip to content

Commit

Permalink
fix: restore default export for backwards compat
Browse files Browse the repository at this point in the history
Brings back default exports for backwards compatibility, but this time in a way that works with AMD and CJS module formats without build tool hacks. Uses rollup-plugin-dts to generate the type declaration for the bundle output, removing the brittle regex-based wrangling we were doing.
  • Loading branch information
trusktr committed Oct 20, 2020
1 parent 04788de commit 825bd2b
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 188 deletions.
181 changes: 49 additions & 132 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Super simple, fast and easy to use tweening engine which incorporates optimised Robert Penner's equations.",
"version": "18.6.0",
"main": "dist/tween.cjs.js",
"types": "dist/index.d.ts",
"types": "dist/tween.d.ts",
"module": "dist/tween.esm.js",
"files": [
"dist",
Expand All @@ -25,12 +25,10 @@
],
"dependencies": {},
"scripts": {
"build": "rimraf dist && rimraf .tmp && node scripts/write-version.js && npm run tsc && npm run rollup-build && npm run tsc-d.ts && npm run adjust-d.ts",
"build": "rimraf dist .tmp && node scripts/write-version.js && npm run tsc && npm run rollup-build",
"rollup-build": "rollup -c ./rollup.config.js",
"tsc": "tsc",
"tsc-watch": "tsc --watch",
"tsc-d.ts": "tsc --declaration --emitDeclarationOnly --esModuleInterop --outFile dist/index.d.ts",
"adjust-d.ts": "node scripts/adjust-d.ts.js",
"test": "npm run build && npm run test-unit && npm run test-lint",
"test-unit": "nodeunit test/unit/nodeunitheadless.js",
"test-lint": "npm run prettier -- --check && eslint 'src/**/*.ts'",
Expand All @@ -52,7 +50,8 @@
"nodeunit": "^0.11.3",
"prettier": "^2.0.0",
"rimraf": "^3.0.0",
"rollup": "^0.57.1",
"rollup": "^2.0.0",
"rollup-plugin-dts": "1.4.10",
"tslib": "^1.10.0",
"typescript": "^4.0.0"
}
Expand Down
57 changes: 33 additions & 24 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
export default {
input: '.tmp/Index.js',
// https://github.com/rollup/rollup/wiki/Troubleshooting#this-is-undefined
context: 'this',
output: [
{
file: 'dist/tween.umd.js',
name: 'TWEEN',
format: 'umd',
},
{
file: 'dist/tween.amd.js',
format: 'amd',
},
{
file: 'dist/tween.cjs.js',
format: 'cjs',
},
{
file: 'dist/tween.esm.js',
format: 'es',
},
],
}
import dts from 'rollup-plugin-dts'

export default [
{
input: '.tmp/Index.js',
// https://github.com/rollup/rollup/wiki/Troubleshooting#this-is-undefined
context: 'this',
output: [
{
file: 'dist/tween.umd.js',
name: 'TWEEN',
format: 'umd',
},
{
file: 'dist/tween.amd.js',
format: 'amd',
},
{
file: 'dist/tween.cjs.js',
format: 'cjs',
},
{
file: 'dist/tween.esm.js',
format: 'es',
},
],
},
{
input: './.tmp/Index.d.ts',
output: [{file: 'dist/tween.d.ts', format: 'es'}],
plugins: [dts()],
},
]
Loading

0 comments on commit 825bd2b

Please sign in to comment.