rollup.config.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import path from 'path'
  2. import external from 'rollup-plugin-peer-deps-external'
  3. import resolve from '@rollup/plugin-node-resolve'
  4. import babel from 'rollup-plugin-babel'
  5. import json from '@rollup/plugin-json'
  6. import typescript from 'rollup-plugin-typescript2'
  7. import commonjs from 'rollup-plugin-commonjs'
  8. import tslint from 'rollup-plugin-tslint'
  9. import stylelint from 'rollup-plugin-stylelint'
  10. import postcss from 'rollup-plugin-postcss'
  11. import { terser } from 'rollup-plugin-terser'
  12. import pkg from './package.json'
  13. const paths = {
  14. input: path.join(__dirname, '/src/pages/view/NotebookPreview.tsx'),
  15. output: path.join(__dirname, '/lib')
  16. }
  17. const peerDependencies = ['react', 'react-dom', 'lodash', 'prop-types']
  18. export default {
  19. input: paths.input,
  20. output: [
  21. // 输出 commonjs 规范的代码
  22. {
  23. file: path.join(paths.output, 'index.js'),
  24. format: 'cjs',
  25. name: pkg.name
  26. },
  27. // 输出 es 规范的代码
  28. {
  29. file: path.join(paths.output, 'index.esm.js'),
  30. format: 'es',
  31. name: pkg.name
  32. }
  33. ],
  34. plugins: [
  35. json(),
  36. external(),
  37. stylelint(),
  38. tslint({
  39. throwOnError: true,
  40. throwOnWarning: true,
  41. include: ['src/**/*.ts', 'src/**/*.tsx'],
  42. exclude: ['node_modules/**', '*.js', '*.scss', '*.css']
  43. }),
  44. typescript(),
  45. babel({
  46. exclude: 'node_modules/**'
  47. }),
  48. commonjs({
  49. include: 'node_modules/**',
  50. namedExports: {
  51. 'node_modules/react-is/index.js': [
  52. 'isFragment',
  53. 'ForwardRef',
  54. 'isValidElementType',
  55. 'isMemo',
  56. 'isElement'
  57. ]
  58. }
  59. }),
  60. // ascii(),
  61. postcss({
  62. // Extract CSS to the same location where JS file is generated but with .css extension.
  63. extract: true,
  64. // Use named exports alongside default export.
  65. namedExports: true,
  66. // Minimize CSS, boolean or options for cssnano.
  67. minimize: true,
  68. // Enable sourceMap.
  69. sourceMap: false,
  70. // This plugin will process files ending with these extensions and the extensions supported by custom loaders.
  71. extensions: ['.less', '.css'],
  72. use: ['sass', ['less', { javascriptEnabled: true }]]
  73. }),
  74. terser(),
  75. resolve()
  76. ],
  77. external: peerDependencies
  78. }