rollupElectronConfig.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import path from 'path';
  2. import { RollupOptions } from 'rollup';
  3. import { nodeResolve } from '@rollup/plugin-node-resolve';
  4. import commonjs from '@rollup/plugin-commonjs';
  5. import esbuild from 'rollup-plugin-esbuild';
  6. import alias from '@rollup/plugin-alias';
  7. import json from '@rollup/plugin-json';
  8. export function getRollupOptions(): RollupOptions {
  9. return {
  10. input: path.join(__dirname, '../../electron-main/index.ts'),
  11. output: {
  12. file: path.join(__dirname, '../../dist/main/build.js'),
  13. format: 'cjs',
  14. name: 'ElectronMainBundle',
  15. sourcemap: true,
  16. },
  17. plugins: [
  18. nodeResolve({ preferBuiltins: true, browser: true }), // 消除碰到 node.js 模块时⚠警告
  19. commonjs(),
  20. json(),
  21. esbuild({
  22. // All options are optional
  23. include: /\.[jt]sx?$/, // default, inferred from `loaders` option
  24. exclude: /node_modules/, // default
  25. // watch: process.argv.includes('--watch'), // rollup 中有配置
  26. sourceMap: false, // default
  27. minify: process.env.NODE_ENV === 'production',
  28. target: 'es2017', // default, or 'es20XX', 'esnext'
  29. jsxFactory: 'React.createElement',
  30. jsxFragment: 'React.Fragment',
  31. // Like @rollup/plugin-replace
  32. define: {
  33. __VERSION__: '"x.y.z"',
  34. },
  35. // Add extra loaders
  36. loaders: {
  37. // Add .json files support
  38. // require @rollup/plugin-commonjs
  39. '.json': 'json',
  40. // Enable JSX in .js files too
  41. '.js': 'jsx',
  42. },
  43. }),
  44. alias({
  45. entries: [{ find: '/@main/', replacement: path.join(__dirname, '../../electron-main') }],
  46. }),
  47. ],
  48. external: [
  49. 'crypto',
  50. 'assert',
  51. 'fs',
  52. 'util',
  53. 'os',
  54. 'events',
  55. 'child_process',
  56. 'http',
  57. 'https',
  58. 'path',
  59. 'electron',
  60. ],
  61. };
  62. }