rollup.config.js 1.6 KB

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