-
-
Notifications
You must be signed in to change notification settings - Fork 800
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c0f6905
commit f39fc24
Showing
2 changed files
with
52 additions
and
13 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 |
---|---|---|
@@ -1,29 +1,70 @@ | ||
import autoExternal from 'rollup-plugin-auto-external'; | ||
import resolveNode from '@rollup/plugin-node-resolve'; | ||
import generatePackageJson from 'rollup-plugin-generate-package-json'; | ||
import rollupTypescript from 'rollup-plugin-typescript2'; | ||
|
||
const commonOutputOptions = { | ||
preferConst: true, | ||
sourcemap: true | ||
sourcemap: true, | ||
}; | ||
|
||
export default { | ||
input: 'src/index.ts', | ||
plugins: [ | ||
resolveNode(), | ||
autoExternal({ builtins: true, dependencies: true, peerDependencies: true }), | ||
rollupTypescript() | ||
autoExternal({ | ||
builtins: true, | ||
dependencies: true, | ||
peerDependencies: true, | ||
}), | ||
generatePackageJson({ | ||
baseContents: rewritePackageJson, | ||
}), | ||
rollupTypescript(), | ||
], | ||
output: [ | ||
{ | ||
...commonOutputOptions, | ||
file: 'dist/index.cjs.js', | ||
format: 'cjs' | ||
format: 'cjs', | ||
}, | ||
{ | ||
...commonOutputOptions, | ||
file: 'dist/index.esm.js', | ||
format: 'esm' | ||
} | ||
] | ||
format: 'esm', | ||
}, | ||
], | ||
}; | ||
|
||
function rewritePackageJson(pkg) { | ||
const newPkg = {}; | ||
const fields = [ | ||
'name', | ||
'version', | ||
'description', | ||
'sideEffects', | ||
'peerDependencies', | ||
'repository', | ||
'homepage', | ||
'keywords', | ||
'author', | ||
'license', | ||
'engines', | ||
]; | ||
|
||
fields.forEach((field) => { | ||
if (pkg[field]) { | ||
newPkg[field] = pkg[field]; | ||
} | ||
}); | ||
|
||
newPkg.main = 'index.cjs.js'; | ||
newPkg.module = 'index.esm.js'; | ||
newPkg.typings = 'index.d.ts'; | ||
newPkg.types = 'index.d.ts'; | ||
newPkg.typescript = { | ||
definition: newPkg.typings, | ||
}; | ||
|
||
return newPkg; | ||
} |