rollup.config.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import nodeResolve from '@rollup/plugin-node-resolve'
  2. import commonjs from "@rollup/plugin-commonjs"
  3. import babel from '@rollup/plugin-babel'
  4. import terser from '@rollup/plugin-terser';
  5. import json from '@rollup/plugin-json'
  6. import ts from "rollup-plugin-typescript2"
  7. const extensions = [".js", ".ts"]
  8. const reserved = ['ComPDFKitJS', 'DataArray', 'LineType', 'PageSize', 'Rect', 'RGBColor', 'FontDa', 'PDFDestination', 'WidgetItem', 'WidgetItemsArray', 'TextFindItemArray', 'EditCharPlace', 'EndEditCharPlace', 'RectArray', 'CursorPoints', 'EditTextStyle', 'U8StringData', 'PDFRange', 'TextRectArray']
  9. const plugins = [
  10. json(),
  11. ts(),
  12. nodeResolve({
  13. preferBuiltins: true,
  14. mainFields: ['browser']
  15. }),
  16. commonjs(),
  17. babel({
  18. extensions,
  19. exclude: 'node_modules/**', // 防止打包node_modules下的文件
  20. // 使用预设
  21. presets: [['@babel/preset-env', {
  22. "modules": false,
  23. // 目标浏览器
  24. "targets": {
  25. "edge": '17',
  26. "firefox": '60',
  27. "chrome": '67',
  28. "safari": '10.0',
  29. 'ie': '10',
  30. },
  31. }]]
  32. })
  33. ]
  34. plugins.push(
  35. terser({
  36. mangle: {
  37. reserved
  38. }
  39. }))
  40. export default [{
  41. input: "./src/worker/compdfkit_worker.js",
  42. output: [
  43. {
  44. format: "es",
  45. file: "../webview/lib/PDFWorker.js"
  46. }
  47. // {
  48. // format: "es",
  49. // name: 'ComPDFKitViewer',
  50. // file: "./dist/webviewer.js",
  51. // sourcemap: false
  52. // }
  53. ],
  54. plugins
  55. },
  56. {
  57. input: "./src/index.js",
  58. output: [
  59. {
  60. format: "es",
  61. file: "../webview/lib/webview.min.js"
  62. }
  63. ],
  64. plugins
  65. }];