Created
February 25, 2023 15:10
-
-
Save nwellis/4f482cbd3d59e0183dfdb404a4ee032b to your computer and use it in GitHub Desktop.
Rollup TS library
This file contains hidden or 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
{ | |
"name": "package-name", | |
"version": "0.9.0", | |
"description": "", | |
"main": "dist/index.cjs.js", | |
"module": "dist/index.esm.js", | |
"browser": "dist/index.umd.js", | |
"types": "dist/index.d.ts", | |
"dependencies": { | |
"ms": "^2.1.3" | |
}, | |
"devDependencies": { | |
"@rollup/plugin-commonjs": "^24.0.1", | |
"@rollup/plugin-json": "^6.0.0", | |
"@rollup/plugin-node-resolve": "^15.0.1", | |
"@rollup/plugin-typescript": "^11.0.0", | |
"@types/ms": "^0.7.31", | |
"rollup": "^2.79.1", | |
"tslib": "^2.5.0" | |
}, | |
"scripts": { | |
"build": "rollup -c", | |
"watch": "rollup -c -w" | |
}, | |
"files": [ | |
"dist" | |
] | |
} |
This file contains hidden or 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
// rollup.config.js | |
import { nodeResolve } from '@rollup/plugin-node-resolve'; | |
import commonjs from '@rollup/plugin-commonjs'; | |
import typescript from '@rollup/plugin-typescript'; | |
import json from '@rollup/plugin-json'; | |
import path from 'path'; | |
import pkg from './package.json'; | |
const ignoredWarnings = [ | |
...[ | |
'node_modules/@auguryfinance/eternity-client-lib' | |
].map(ignoredPath => ({ | |
ignoredCode: 'CIRCULAR_DEPENDENCY', | |
ignoredPath, | |
})) | |
] | |
// https://github.com/rollup/rollup/issues/1089 | |
const onwarn = (warning, rollupWarn) => { | |
if (!ignoredWarnings.some(({ ignoredCode, ignoredPath }) => ( | |
warning.code === ignoredCode && | |
warning.importer?.startsWith(path.normalize(ignoredPath)))) | |
) { | |
rollupWarn(warning) | |
} | |
} | |
// `npm run build` -> `production` is true | |
// `npm run dev` -> `production` is false | |
const production = !process.env.ROLLUP_WATCH; | |
/** @type {import('rollup').InputOptions} */ | |
export default [ | |
// Browser | |
{ | |
input: 'src/index.ts', | |
output: { | |
name: pkg.name, file: pkg.main, format: 'umd', sourcemap: true | |
}, | |
plugins: [ | |
nodeResolve({ preferBuiltins: true }), | |
commonjs(), | |
json(), | |
typescript(), | |
], | |
// https://github.com/rollup/rollup/issues/1089 | |
onwarn, | |
}, | |
// Node | |
{ | |
input: 'src/index.ts', | |
output: [ | |
{ file: pkg.main, format: 'cjs', sourcemap: true }, | |
{ file: pkg.module, format: 'es', sourcemap: true }, | |
], | |
plugins: [ | |
json(), | |
typescript(), | |
], | |
external: [ | |
'ms' | |
], | |
onwarn, | |
}, | |
] |
This file contains hidden or 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
Show hidden characters
{ | |
"compilerOptions": { | |
"strict": false, | |
"moduleResolution": "node", | |
"target": "ES2022", | |
"module":"es2015", | |
"lib": ["es2015", "es2016", "es2017", "dom"], | |
"sourceMap": true, | |
"declaration": true, | |
"allowSyntheticDefaultImports": true, | |
"experimentalDecorators": true, | |
"emitDecoratorMetadata": true, | |
"declarationDir": "dist/types", | |
"outDir": "dist", | |
"typeRoots": [ | |
"node_modules/@types" | |
] | |
}, | |
"include": [ | |
"./src" | |
], | |
"exclude": [ | |
"node_modules", | |
"dist" | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment