build.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* eslint-disable */
  2. // npm install rollup-plugin-typescript2 typescript --save-dev
  3. import typescript from 'rollup-plugin-typescript2'
  4. // import { terser } from 'rollup-plugin-terser'
  5. // import resolve from 'rollup-plugin-node-resolve'
  6. // ------------------------------------------------------------------------------------------
  7. // formats
  8. // ------------------------------------------------------------------------------------------
  9. // amd – Asynchronous Module Definition, used with module loaders like RequireJS
  10. // cjs – CommonJS, suitable for Node and Browserify/Webpack
  11. // esm – Keep the bundle as an ES module file
  12. // iife – A self-executing function, suitable for inclusion as a <script> tag. (If you want to create a bundle for your application, you probably want to use this, because it leads to smaller file sizes.)
  13. // umd – Universal Module Definition, works as amd, cjs and iife all in one
  14. // system – Native format of the SystemJS loader
  15. // ------------------------------------------------------------------------------------------
  16. // setup
  17. // ------------------------------------------------------------------------------------------
  18. const pkg = require('./package.json')
  19. const name = pkg.name
  20. const className = name.replace(/(^\w|-\w)/g, c => c.replace('-', '').toUpperCase())
  21. const external = Object.keys(pkg.dependencies || [])
  22. const plugins = [
  23. typescript({ useTsconfigDeclarationDir: true, tsconfigOverride: { exclude: ['test/**/*'] } }),
  24. ]
  25. // ------------------------------------------------------------------------------------------
  26. // Builds
  27. // ------------------------------------------------------------------------------------------
  28. function defaults (config) {
  29. // defaults
  30. const defaults = {
  31. plugins,
  32. external,
  33. }
  34. // defaults.output
  35. config.output = config.output.map(output => {
  36. return Object.assign(
  37. {
  38. sourcemap: false,
  39. name: className,
  40. exports: 'named',
  41. },
  42. output
  43. )
  44. })
  45. return Object.assign(defaults, config)
  46. }
  47. export default [
  48. defaults({
  49. input: 'src/index.ts',
  50. output: [
  51. { file: 'dist/index.cjs.js', format: 'cjs' },
  52. { file: 'dist/index.esm.js', format: 'esm' },
  53. ],
  54. }),
  55. ]